How can I detect when the .NET Framework feature is "turned off" in Windows 7 / Vista?
Asked Answered
N

3

11

My application requires the .NET Framework version 3.5. I recently ran into a customer that had the .NET Framework installed but turned off on Windows Vista (also applies to Windows 7).

In this case, my installer (InstallShield 2009) does not prompt the user to install the Framework (because it is already installed) and when my application runs it crashes immediately. I tried another .NET application and it also crashes immediately.

Is there any way to detect this situation and handle it more gracefully? Just detecting this during install is not ideal since the .NET Framework can be turned off at any time. Ideally, the application would be able to check and display a friendly message to the user telling them they need to turn on the .NET Framework.

EDIT: "Turning off" the .NET Framework in Windows Vista or Windows 7 is not the same as uninstalling it. The Framework can be simply turned back on without reinstalling: http://windows.microsoft.com/en-US/windows-vista/Turn-Windows-features-on-or-off

Norway answered 19/4, 2010 at 18:35 Comment(8)
I've never heard that the .NET Framework could be turned off. You need a better description of the situation, maybe from the customer.Daven
I always thought (assumed) that doing this was the same as uninstalling.Nightrider
@John, @dkackman. Turning off a feature in Windows 7 does not uninstall the feature, it is simply turned off or disabled.Dichlorodiphenyltrichloroethane
@Chris: he also didn't say Windows 7. Added to the tags.Daven
@John, actually Vista also supports the Feature On/Off paradigm. It was just habit that I typed Windows 7.Dichlorodiphenyltrichloroethane
Just a thought. I don't currently have the time to disable .NET on my Windows 7 machine, but dig around the registry near HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\policy\v2.0. Are there any registry keys that change or disappear when the feature is "turned off"? If so, you should be able to check registry keys without elevation.Allanadale
It would be nice if the CLR loader would detect this state and give a friendly indication that "This application cannot run because you have disabled the .NET Framework feature. Please 'click here' to manage your enabled features." Then again, I had always hoped for something similar on failing to resolve dependent assemblies...Warrantor
Also, the registry keys referenced by support.microsoft.com/kb/928637 might change?Allanadale
S
8

When I turned off the feature, the value in the registry that indicated the framework is installed got deleted. You could check that value.

Take a look at: HKLM\Software\Microsoft\NET Framework Setup\NDP\v3.5

Sarson answered 19/4, 2010 at 18:50 Comment(2)
Thanks, so I can check that registry key but I would have to do it from and un-managed launcher, right?Norway
Yeah, unfortunately there won't be a way around that since the feature can be turned off and on at will.Sarson
A
3

Looks like you're going to write a non-managed launcher for your app. Roll up your sleeves and have a nice C++ dive :)

Albany answered 19/4, 2010 at 18:51 Comment(0)
O
1

Woot, I think this URL might have your answer:

http://blogs.msdn.com/astebner/archive/2008/04/04/8358995.aspx

See "How to install the .NET Framework 3.0 OS component in a deployment scenario". It describes using ocsetup to trigger Windows to turn the feature on, as far as I can tell. Best of luck.

Also, I'm curious if ClickOnce installers are intelligent to know if the feature is turned off (I imagine they would be). But since you're using InstallShield you probably want a more fully-featured installer than clickonce ;o)

Oilla answered 19/4, 2010 at 18:55 Comment(1)
The solution I mentioned is for .NET 3 but I bet you can use the same approach for 3.5.Oilla

© 2022 - 2024 — McMap. All rights reserved.