Caracol Posted March 21, 2011 Share Posted March 21, 2011 Hi all, 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! Link to comment Share on other sites More sharing options...
Bert Posted March 21, 2011 Share Posted March 21, 2011 Ummm, how is this an AutoIt question? If you are making a AutoIt script, then why the need for .NET? The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Caracol Posted March 21, 2011 Author Share Posted March 21, 2011 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 Link to comment Share on other sites More sharing options...
Bert Posted March 21, 2011 Share Posted March 21, 2011 Ah, OK, you could check in the registry for it. All you need to know is the key. That would be the simplest way. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Caracol Posted March 21, 2011 Author Share Posted March 21, 2011 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-installedI'll see if I can put the uninstall registry key to use.Cheers Link to comment Share on other sites More sharing options...
Mallie99 Posted March 21, 2011 Share Posted March 21, 2011 If it helps, I have a little procedure for doing just that: ; #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 Are you telling me something I need to know or something I want to know? Link to comment Share on other sites More sharing options...
Ascend4nt Posted March 22, 2011 Share Posted March 22, 2011 (edited) Here's a function and example I wrote up to get the .NET version(s) installed (or uninstalled): expandcollapse popup; ========================================================================================================================== ; 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': ; @ http://msdn.microsoft.com/en-us/kb/kbarticle.aspx?id=318785 ; ; $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 March 22, 2011 by Ascend4nt yahaosoft 1 My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _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 | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
Caracol Posted March 22, 2011 Author Share Posted March 22, 2011 (edited) Good stuff, thanks! 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 March 22, 2011 by Caracol Link to comment Share on other sites More sharing options...
Ascend4nt Posted March 22, 2011 Share Posted March 22, 2011 Caracol, np. 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 | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _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 | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now