How to check if .NET is present on the PC
#1
Posted 21 March 2011 - 02:57 PM
I want a script to run and tell me whether the machine on which it's running has .NET installed or not.
Any advice?
Thanks!
#2
Posted 21 March 2011 - 03:00 PM
If you are making a AutoIt script, then why the need for .NET?
#3
Posted 21 March 2011 - 03:03 PM
Ummm, how is this an AutoIt question?
If you are making a AutoIt script, then why the need for .NET?
Hi MPH,
I don't need .NET for autoit, I need it for something else, but I want to use autoit script to check whether .NET is present or not as a condition for running a set of commands.
Thanks again
#4
Posted 21 March 2011 - 03:07 PM
#5
Posted 21 March 2011 - 03:11 PM
Ah, OK, you could check in the registry for it. All you need to know is the key. That would be the simplest way.
Good idea, thanks!
Found this:
http://bytes.com/topic/net/answers/121177-test-if-net-installed
I'll see if I can put the uninstall registry key to use.
Cheers
#6
Posted 21 March 2011 - 03:50 PM
; #APPINSTALLED# =============================================================================================================== ; Author........: Pete Mallam ; Date..........: 12/02/2010 ; Description...: Simple function to check if the application is installed by checking the GUID against the Uninstall section ; of the Windows Registry ; Returns.......: Returns TRUE if the application is installed, FALSE if the application is not installed ; ; Modification History: ; -> [11/03/2011] Cleaned up how the GUID is passed by now including the {} surrounding the GUID (Mal) ; ============================================================================================================================== Func AppInstalled($GUID) $Uninstall = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $GUID, "Version") If @error Then Return False Else Return True EndIf EndFunc ;==>AppInstalled ; ==============================================================================================================================
Useage:
If AppInstalled({B43357AA-3A6D-4D94-B56E-43C44D09E548}) Then MsgBox(16, "Test", "It is installed")
Mal
#7
Posted 22 March 2011 - 12:00 AM
; ========================================================================================================================== ; Func _dotNetGetVersions($bOnlyInstalled=False) ; ; Function to return information on which .NET versions are/were installed. ; NOTES: No Service Pack information is retrieved, although that can be obtained using the methods ; in the MSDN link below. ; ; Also NOTE: As with anything I program (in full or part), keep the header WITH the function if used or shared. ; ; .NET Framework detection resource: ; MSDN KB318785: 'How to determine which versions and service pack levels of the Microsoft .NET Framework are installed': ; @ <a href='http://msdn.microsoft.com/en-us/kb/kbarticle.aspx?id=318785' class='bbc_url' title='External link' rel='nofollow external'>http://msdn.microsoft.com/en-us/kb/kbarticle.aspx?id=318785</a> ; ; $bOnlyInstalled = If True, it will not report on any versions that were uninstalled ; ; Returns: ; Success: An array of information, as follows: ; [0][0] = Total # found ; [x][0] = Numerical version (can be whole number or floating point [1, 1.1, 2, 3, 3.5, 4]) ; [x][1] = Full version name string - this can be used to probe further sub-version info (example: "v2.0.50727") ; [x][2] = 0 or 1 - indicates whether 'client' or normal installation is installed ; (From version 4+, there can be a client and/or a full install - though full seems to install client.) ; [x][3] = 0 or 1 - indicates whether 'full' install of the .NET component is installed (version 4+ only) ; Failure: '' and @error set: ; @error = -3 = .NET key could not be read, or .NET is not installed (the latter *most* likely) ; (@extended returns @error state from last Reg* call.) ; ; Author: Ascend4nt ; ========================================================================================================================== Func _dotNetGetVersions($bOnlyInstalled=False) Local $i=1,$iClientInstall,$iFullInstall,$iNum,$aVersions[100][4],$iTotal=0,$bVer4Found=0 Local $sKey="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP",$sSubKey ; Detect v1.0 (special key) RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\.NETFramework\Policy\v1.0","3705") ; If value was read (key exists), and is of type REG_SZ (1 as defined in <Constants.au3>), v1.0 is installed If @error=0 And @extended=1 Then $iTotal+=1 $aVersions[$iTotal][0]=1.0 $aVersions[$iTotal][1]='v1.0.3705' $aVersions[$iTotal][2]=1 $aVersions[$iTotal][3]=1 EndIf While 1 $iClientInstall=0 $iFullInstall=0 $sSubKey=RegEnumKey($sKey,$i) If @error Then ExitLoop $i+=1 ; 'v4.0' is a deprecated version. Since it comes after 'v4' (the newer version) while enumerating, ; a simple check if 'v4' has already been found is sufficient If $sSubKey='v4.0' And $bVer4Found Then ContinueLoop $iNum=Number(StringMid($sSubKey,2)) ; cuts off at any 2nd decimal points (obviously) ; Note - one of the SubKeys is 'CDF'. Number() will return 0 in this case [we can safely ignore that] If $iNum=0 Then ContinueLoop ;~ ConsoleWrite(".NET Framework SubKey #"&$i&": "&$sSubKey&", Number extracted (0 for non-versioned items):"&$iNum&@LF) If $iNum<4 Then $iClientInstall=RegRead($sKey&'\'&$sSubKey,'Install') If $iClientInstall Then $iFullInstall=1 ; older versions were all-or-nothing I believe ;~ If @error Then $iClientInstall=0 ; (@error from $iClientInstall) -> caught below Else ; Version 4 works with one or both of these keys. One can only hope new versions keep the same organization $iFullInstall=RegRead($sKey&'\'&$sSubKey&'\Full','Install') If @error Then $iFullInstall=0 $iClientInstall=RegRead($sKey&'\'&$sSubKey&'\Client','Install') ;~ If @error Then $iClientInstall=0 ; Caught below If $iNum<5 Then $bVer4Found=True EndIf If @error Then $iClientInstall=0 If $bOnlyInstalled And $iClientInstall=0 And $iFullInstall=0 Then ContinueLoop $iTotal+=1 $aVersions[$iTotal][0]=$iNum $aVersions[$iTotal][1]=$sSubKey $aVersions[$iTotal][2]=$iClientInstall $aVersions[$iTotal][3]=$iFullInstall WEnd If $iTotal=0 Then Return SetError(-3,@error,'') $aVersions[0][0]=$iTotal ReDim $aVersions[$iTotal+1][4] Return $aVersions EndFunc ; ------- TEST ---------- #include <Array.au3> $adotNetVersions=_dotNetGetVersions() $adotNetVersions[0][0]="Main Version #" $adotNetVersions[0][1]="Full version string" $adotNetVersions[0][2]="Client/General Install?" $adotNetVersions[0][3]="Full Install?" _ArrayDisplay($adotNetVersions,'.NET versions')
*edit: $bVer4Found adjustment (for when/if v.5 comes out..), 2nd edit: $iFullInstall logic error
*edit again - put in check for version 1.0 also (different registry key), made note about ServicePacks (not detected)
Edited by Ascend4nt, 22 March 2011 - 07:23 AM.
My contributions:
Performance Counters in Windows - Measure CPU,Disk,Network etc Performance | Process, Thread, & DLL Functions UDFs | CPU Multi-Processor Usage w/o Performance Counters | Windows Desktop Dimmer Shade | CrossHairs (FullScreen) | _EnumChildWindows (controls etc) | Rubber-Band Boxes using GUI's (_GUIBox) | File + Process Imports/Exports Information | _DLLStructDisplay (Debug!) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Full-Screen Crash Recovery
Wrappers/Modifications of others' contributions:
_DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity)
UDF's added support/programming to:
_ExplorerWinGetSelectedItems | MIDI UDF (original code: eynstyne)
(All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)
#8
Posted 22 March 2011 - 11:44 AM
I eventually ended up with this simple code:
SetError(0)
RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5\","Install")
If @error <> 0 Then
MsgBox(0,"Info", ".NET v3.5 or higher is required!")
EndIf
As it turns out this key will always be present if v3.5 is installed. Also, .NET installs prior versions during the installation process of any version, so if a higher version of .NET is installed, this key will definitely be found.
I have done the same to see if there is a PDF viewer installed on the machine:
SetError(0)
RegRead("HKEY_CLASSES_ROOT\.pdf","")
If @error <> 0 Then
MsgBox(0,"Info", "A pdf reader is required.")
EndIf
Thanks all for your swift and helpful replies!
Ascend4nt - I found your code sample very useful for other things too
Edited by Caracol, 22 March 2011 - 11:46 AM.
#9
Posted 22 March 2011 - 08:49 PM
Btw - you might want to check that the 'Install' value is 1, because it will supposedly be left over if someone uninstalls that version of .NET (haven't tested it yet, but its a simple check you should use).
Also, no need to use SetError(0) before any function call, including AutoIt's built-in functions - the @error and @extended values are both affected by every call.
My contributions:
Performance Counters in Windows - Measure CPU,Disk,Network etc Performance | Process, Thread, & DLL Functions UDFs | CPU Multi-Processor Usage w/o Performance Counters | Windows Desktop Dimmer Shade | CrossHairs (FullScreen) | _EnumChildWindows (controls etc) | Rubber-Band Boxes using GUI's (_GUIBox) | File + Process Imports/Exports Information | _DLLStructDisplay (Debug!) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Full-Screen Crash Recovery
Wrappers/Modifications of others' contributions:
_DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity)
UDF's added support/programming to:
_ExplorerWinGetSelectedItems | MIDI UDF (original code: eynstyne)
(All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users



