How to detect .Net framework installed or not.


This is another frequently asked question.


If you search google how to detect .Net Framework, this(http://support.microsoft.com/default.aspx?scid=kb;%5BLN%5D;315291) page ranks very high.


Ignore all the details in the KB articles. It basically asks you to check this reg key. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\policy\v1.0]. If REG_SZ value 3705 exists, then .Net framework v1 is installed.


The same can be applied to detect v1.1. Instead, you check [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\policy\v1.1], and test the existence of REG_SZ value 4322.


But wait, there is another not-so-well known documented way to detech existence of .Net framework v1.1. And it is not even in the first 10 pages of google hits.


Redistributing the .Net framework 1.1


It tells you how to detect .Net framework 1.1. And more! It also tells you how to detect the language pack, and J# package!


Should I say this is a failure of google, or Microsoft?:)

Comments (13)

  1. Simon says:

    http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=redistributing+the+.net+framework

    Google seems to be spot on when you ask for redistributing rather than detecting.

  2. A question that may be related: for detecting IIS 5.0 or higher (for ASP.NET), is there a better way than checking the registry?

  3. Well, I do not work on IIS team. But can’t you check the OS? If the OS is Win2k, it is IIS 5.0. If the OS is WinXP, it is IIS 5.1. If the OS is Win2003, it is IIS 6.0.

    I don’t think IIS ever ships out of band.

    For your purpose, you just need to make sure the OS is 1. NT, 2. Major version is 5+.

  4. moo says:

    If I add dotnetfx.exe to the Custom Actions view under "Install". And set my command line to /q:a /c:"install /l /q" I get the usual "its already installed" messageBox.

    I tried to use "Installed == false" in the Condition property yet that doesnt work.

    How can I do this within the setup project in Visual Studio? I certinally hope I dont have to write a DLL assembly to do this as thats OVERKILL.

  5. moo,

    Isn’t the first link (http://support.microsoft.com/default.aspx?scid=kb;%5BLN%5D;315291) tells you how to detect .Net framework in a deployment package?

  6. Doing things the hard way with RSS Bandit leads to some interesting statistics; Stuff for my Boss and co-workers; SOA and Joe Developer — Phillip gets it right (again); Bits on Reporting Services; Wake up and smell RSS.NET; htmlArea (drool); InfoPath duh; McD’s

  7. Anonymous Developer says:

    If I write a VB app in VB.NET.. How can I detect if Framwork is installed? Seems like a chicken and egg problem.. if Framework is installed, then the app will not cause error…. Hummm..

  8. It does not make sense to detect framework in a managed application. Instead, you should detect framework in your deployment package. Follow the link in the original post.

  9. Raymond W. Six says:

    Here’s a VBScript for Windows Scripting Host (WSH) that implements detection of various system items, including:

    Operating System Product

    Operating System Version

    Operating System Build

    Operating System Service Pack

    Is this a server? (true/false)

    .NET Framework (true/false)

    .NET Framework 1.0 (true/false)

    .NET Framework 1.1 (true/false)

    I actually use this in a login script to gather information about various computers on the domain.

    Anyway, hope this helps anyone interested…





    ‘ Preperation Stuff

    ‘ =================





    ‘ To enable error display, start this script with

    ‘ the command-line parameter "/errors:YES"



    if UCase(WScript.Arguments.Named.Item("errors")) = "YES" then

    rwsErrors = TRUE

    on error goto 0

    else

    rwsErrors = FALSE

    on error resume next

    end if



    ‘ To enable debug mode, start this script with

    ‘ the command-line parameter "/debug:YES"



    if UCase(WScript.Arguments.Named.Item("debug")) = "YES" then

    rwsDebug = TRUE

    else

    rwsDebug = FALSE

    end if





    ‘ Function and Procedure Definitions

    ‘ ==================================

    ‘ NOTE: Don’t mess with this section!





    ‘ Define a function to detect if the

    ‘ .NET Framework is installed…



    function rwsDetectDotNet



    ‘ If in debug mode, tell the user that this

    ‘ fuction was invoked, and what parameter(s)

    ‘ were passed to it…



    if rwsDebug = True then

    WScript.Echo "Called = rwsDetectDotNet"

    end if



    ‘ Define variables that this function needs…



    dim objShell

    dim dotNetAny

    dim RegKeyValue

    dim ReturnValue



    ‘ Use the Shell object to query

    ‘ the registry for .NET settings…



    ReturnValue = FALSE

    set objShell = WScript.CreateObject("WScript.Shell")

    on error resume next

    RegKeyValue = objShell.RegRead ("HKEY_LOCAL_MACHINESOFTWAREMicrosoft.NETFrameworkInstallRoot")

    err.clear

    if rwsErrors = TRUE then

    on error goto 0

    end if

    if RegKeyValue <> "" then

    ReturnValue = TRUE

    else

    ReturnValue = FALSE

    end if

    rwsDetectDotNet = ReturnValue



    ‘ If in debug mode, tell the user

    ‘ what the return value was…



    if rwsDebug = True then

    if ReturnValue = TRUE then

    WScript.Echo "rwsDetectDotNet = TRUE"

    else

    WScript.Echo "rwsDetectDotNet = FALSE"

    end if

    end if



    ‘ … That’s all for this function.



    end function



    ‘ Define a function to detect if the

    ‘ .NET Framework version 1.0 is installed…



    function rwsDetectDotNetV10



    ‘ If in debug mode, tell the user that this

    ‘ fuction was invoked, and what parameter(s)

    ‘ were passed to it…



    if rwsDebug = True then

    WScript.Echo "Called = rwsDetectDotNetV10"

    end if



    ‘ Define variables that this function needs…



    dim objShell

    dim dotNetAny

    dim RegKeyValue

    dim ReturnValue



    ‘ Use the Shell object to query

    ‘ the registry for .NET settings…



    ReturnValue = FALSE

    set objShell = WScript.CreateObject("WScript.Shell")

    on error resume next

    RegKeyValue = objShell.RegRead ("HKEY_LOCAL_MACHINESOFTWAREMicrosoft.NETFrameworkpolicyv1.03705")

    err.clear

    if rwsErrors = TRUE then

    on error goto 0

    end if

    if RegKeyValue <> "" then

    ReturnValue = TRUE

    else

    ReturnValue = FALSE

    end if

    rwsDetectDotNetV10 = ReturnValue



    ‘ If in debug mode, tell the user

    ‘ what the return value was…



    if rwsDebug = True then

    if ReturnValue = TRUE then

    WScript.Echo "rwsDetectDotNetV10 = TRUE"

    else

    WScript.Echo "rwsDetectDotNetV10 = FALSE"

    end if

    end if



    ‘ … That’s all for this function.



    end function



    ‘ Define a function to detect if the

    ‘ .NET Framework version 1.1 is installed…



    function rwsDetectDotNetV11



    ‘ If in debug mode, tell the user that this

    ‘ fuction was invoked, and what parameter(s)

    ‘ were passed to it…



    if rwsDebug = True then

    WScript.Echo "Called = rwsDetectDotNetV11"

    end if



    ‘ Define variables that this function needs…



    dim objShell

    dim dotNetAny

    dim RegKeyValue

    dim ReturnValue



    ‘ Use the Shell object to query

    ‘ the registry for .NET settings…



    ReturnValue = FALSE

    set objShell = WScript.CreateObject("WScript.Shell")

    on error resume next

    RegKeyValue = objShell.RegRead ("HKEY_LOCAL_MACHINESOFTWAREMicrosoft.NETFrameworkpolicyv1.14322")

    err.clear

    if rwsErrors = TRUE then

    on error goto 0

    end if

    if RegKeyValue <> "" then

    ReturnValue = TRUE

    else

    ReturnValue = FALSE

    end if

    rwsDetectDotNetV11 = ReturnValue



    ‘ If in debug mode, tell the user

    ‘ what the return value was…



    if rwsDebug = True then

    if ReturnValue = TRUE then

    WScript.Echo "rwsDetectDotNetV11 = TRUE"

    else

    WScript.Echo "rwsDetectDotNetV11 = FALSE"

    end if

    end if



    ‘ … That’s all for this function.



    end function



    ‘ Define a function to determine if the current

    ‘ computer is a workstation or a server…



    function rwsDetectServer



    ‘ Define variables that this function needs…



    dim objShell

    dim RegKey

    dim ReturnValue



    ‘ If in debug mode, tell the user that this

    ‘ fuction was invoked, and what parameter(s)

    ‘ were passed to it…



    if rwsDebug = True then

    WScript.Echo "Called = rwsDetectServer"

    end if



    ‘ Access the registry to determine

    ‘ the operating system edition..



    Set objShell = WScript.CreateObject("WScript.Shell")

    RegKey = objShell.RegRead("HKLMSystemCurrentControlSetControlProductOptionsProductType")



    ‘ If in debug mode, tell the user what value

    ‘ was stored in the registry…



    if rwsDebug = True then

    WScript.Echo "HKEY_LOCAL_MACHINESystemCurrentControlSetControlProductOptionsProductType = " + chr(34) + RegKey + chr(34)

    end if



    ‘ Return a true or false value,

    ‘ depending on the value that was

    ‘ in the registry key.



    select case UCase(RegKey)

    case "NONE"

    rwsDetectServer = FALSE

    case "WINNT"

    rwsDetectServer = FALSE

    case else

    rwsDetectServer = TRUE

    end select



    ‘ … That’s all for this function.



    end function



    ‘ Define a procedure to log operating

    ‘ system version information to a file

    ‘ stored in a central location…



    sub rwsLogData (LogFileUNCName)



    ‘ Define variables that this function needs…



    dim objShell

    dim objFileSystem

    dim objFile

    dim DateTimeString

    dim OSProduct

    dim OSVersion

    dim OSBuild

    dim OSSP

    dim dotNetAny

    dim dotNetV10

    dim dotNetV11

    dim OSCompName

    dim OSServer



    ‘ If in debug mode, tell the user that this

    ‘ fuction was invoked, and what parameter(s)

    ‘ were passed to it…



    if rwsDebug = True then

    WScript.Echo "Called = rwsDetectOS (" + LogFileUNCName + ")"

    end if



    ‘ Create a string that represent’s today’s date/time

    ‘ in "yyyy/mm/dd hh:mm" format to use in the log…



    DateTimeString = CStr(Year(Now))

    if Len(CStr(Month(Now))) < 2 then

    DateTimeString = DateTimeString + "/0" + CStr(Month(Now))

    else

    DateTimeString = DateTimeString + "/" + CStr(Month(Now))

    end if

    if Len(CStr(Day(Now))) < 2 then

    DateTimeString = DateTimeString + "/0" + CStr(Day(Now))

    else

    DateTimeString = DateTimeString + "/" + CStr(Day(Now))

    end if

    if Len(CStr(Hour(Now))) < 2 then

    DateTimeString = DateTimeString + " 0" + CStr(Hour(Now))

    else

    DateTimeString = DateTimeString + " " + CStr(Hour(Now))

    end if

    if Len(CStr(Minute(Now))) < 2 then

    DateTimeString = DateTimeString + ":0" + CStr(Minute(Now))

    else

    DateTimeString = DateTimeString + ":" + CStr(Minute(Now))

    end if



    ‘ Detect various stuff…



    set objShell = WScript.CreateObject("WScript.Shell")

    OSCompName = objShell.ExpandEnvironmentStrings("%COMPUTERNAME%")

    OSProduct = rwsDetectOSProduct

    OSVersion = rwsDetectOSVersion

    OSBuild = rwsDetectOSBuild

    OSSP = rwsDetectOSSP

    if rwsDetectServer = TRUE then

    OSServer = "TRUE"

    else

    OSServer = "FALSE"

    end if

    if rwsDetectDotNet = TRUE then

    dotNetAny = "TRUE"

    else

    dotNetAny = "FALSE"

    end if

    if rwsDetectDotNetV10 = TRUE then

    dotNetV10 = "TRUE"

    else

    dotNetV10 = "FALSE"

    end if

    if rwsDetectDotNetV11 = TRUE then

    dotNetV11 = "TRUE"

    else

    dotNetV11 = "FALSE"

    end if



    ‘ Use the File object to

    ‘ log data to a file…



    Set objFileSystem = CreateObject("Scripting.FileSystemObject")

    Set objFile = objFileSystem.OpenTextFile(LogFileUNCName, 8, TRUE)

    objFile.WriteLine DateTimeString + CHR(9) + OSCompName + CHR(9) + OSProduct + CHR(9) + OSVersion + CHR(9) + OSBuild + CHR(9) + OSSP + CHR(9) + OSServer + CHR(9) + dotNetAny + CHR(9) + dotNetV10 + CHR(9) + dotNetV11

    objFile.Close



    ‘ … That’s all for this function.



    end sub



    ‘ Define a function to detect the

    ‘ operating system product…



    function rwsDetectOSProduct



    ‘ Define variables that this function needs…



    dim objShell

    dim ReturnValue



    ‘ If in debug mode, tell the user that this

    ‘ fuction was invoked, and what parameter(s)

    ‘ were passed to it…



    if rwsDebug = True then

    WScript.Echo "Called = rwsDetectOSProduct"

    end if



    ‘ Use the Shell object to detect

    ‘ the current operating system…



    set objShell = WScript.CreateObject("WScript.Shell")

    ReturnValue = "UNKNOWN"

    on error resume next

    ReturnValue = objShell.RegRead ("HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionProductName")

    err.clear

    if rwsErrors = TRUE then

    on error goto 0

    end if

    rwsDetectOSProduct = ReturnValue



    ‘ If in debug mode, tell the user

    ‘ what the return value was…



    if rwsDebug = True then

    WScript.Echo "rwsDetectOSProduct = " + ReturnValue

    end if



    ‘ … That’s all for this function.



    end function



    ‘ Define a function to detect the

    ‘ operating system version…



    function rwsDetectOSVersion



    ‘ Define variables that this function needs…



    dim objShell

    dim ReturnValue



    ‘ If in debug mode, tell the user that this

    ‘ fuction was invoked, and what parameter(s)

    ‘ were passed to it…



    if rwsDebug = True then

    WScript.Echo "Called = rwsDetectOSVersion"

    end if



    ‘ Use the Shell object to detect

    ‘ the current operating system…



    set objShell = WScript.CreateObject("WScript.Shell")

    ReturnValue = "UNKNOWN"

    on error resume next

    ReturnValue = objShell.RegRead ("HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionCurrentVersion")

    err.clear

    if rwsErrors = TRUE then

    on error goto 0

    end if

    rwsDetectOSVersion = ReturnValue



    ‘ If in debug mode, tell the user

    ‘ what the return value was…



    if rwsDebug = True then

    WScript.Echo "rwsDetectOSVersion = " + ReturnValue

    end if



    ‘ … That’s all for this function.



    end function



    ‘ Define a function to detect the

    ‘ operating system build…



    function rwsDetectOSBuild



    ‘ Define variables that this function needs…



    dim objShell

    dim ReturnValue



    ‘ If in debug mode, tell the user that this

    ‘ fuction was invoked, and what parameter(s)

    ‘ were passed to it…



    if rwsDebug = True then

    WScript.Echo "Called = rwsDetectOSBuild"

    end if



    ‘ Use the Shell object to detect

    ‘ the current operating system…



    set objShell = WScript.CreateObject("WScript.Shell")

    ReturnValue = "UNKNOWN"

    on error resume next

    ReturnValue = objShell.RegRead ("HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionCurrentBuildNumber")

    err.clear

    if rwsErrors = TRUE then

    on error goto 0

    end if

    rwsDetectOSBuild = ReturnValue



    ‘ If in debug mode, tell the user

    ‘ what the return value was…



    if rwsDebug = True then

    WScript.Echo "rwsDetectOSBuild = " + ReturnValue

    end if



    ‘ … That’s all for this function.



    end function



    ‘ Define a function to detect the

    ‘ operating system service pack…



    function rwsDetectOSSP



    ‘ Define variables that this function needs…



    dim objShell

    dim ReturnValue



    ‘ If in debug mode, tell the user that this

    ‘ fuction was invoked, and what parameter(s)

    ‘ were passed to it…



    if rwsDebug = True then

    WScript.Echo "Called = rwsDetectOSSP"

    end if



    ‘ Use the Shell object to detect

    ‘ the current operating system…



    set objShell = WScript.CreateObject("WScript.Shell")

    ReturnValue = "UNKNOWN"

    on error resume next

    ReturnValue = objShell.RegRead ("HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionCSDVersion")

    err.clear

    if rwsErrors = TRUE then

    on error goto 0

    end if

    rwsDetectOSSP = ReturnValue



    ‘ If in debug mode, tell the user

    ‘ what the return value was…



    if rwsDebug = True then

    WScript.Echo "rwsDetectOSSP = " + ReturnValue

    end if



    ‘ … That’s all for this function.



    end function





    ‘ Meat and Potatoes

    ‘ =================



    rwsLogData "\ECD-FS02OSGathering$OSVersionLog.TXT"





    ‘ End of the line

    ‘ ===============



    ‘ If in debug mode, let the user know that

    ‘ the end of the script has been reached…



    if rwsDebug = True then

    WScript.Echo "End of Script"

    end if

  10. No it all :-) says:

    Go to add remove programs and see if it’s listed there. If it is you have it if it isn’t you need to install it. Really simple. Geesh;-)

Skip to main content