Monday, August 16, 2010

An Important Note about the SCCM Scripts

The scripts I posted recently for uninstalling AutoCAD LT 2011 and AutoCAD Civil 3D 2011 are for 32-bit Windows operating systems.  If you are working with 64-bit clients, you may need to add more code to check for 32-bit application registry keys under HKLM\SOFTWARE\Wow6432node, rather than just looking under HKLM\SOFTWARE.  I'm not going to waste my breath explaining why this is, just trust me: it is what it is.  And boy do I hate that overused phrase.

Here is an example of what I'm talking about…

Const strComputer = "."
Const HKLM = &H80000002

Set oShell = CreateObject("Wscript.Shell")

If RegKeyExists("HKLM\Software\Autodesk\DWF Viewer\") Then
wscript.echo "found!"
Else
wscript.echo "not found"
End If

If RegKeyExists("HKLM\Software\Autodesk\AutoCAD\") Then
wscript.echo "found!"
Else
wscript.echo "not found"
End If

If RegKeyExists64("Software\Autodesk", "AutoCAD") Then
wscript.echo "found!"
Else
wscript.echo "not found"
End If

Function RegKeyExists(key)
Dim bKey
On Error Resume Next
bKey = oShell.RegRead(key)
If err.Number = 0 Then
RegKeyExists = True
End If
End Function


Function RegKeyExists64(key, valueName)
Dim objRegistry, strValue
On Error Resume Next
Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
objRegistry.GetStringValue HKLM, key, valueName, strValue
If err.Number = 0 Then
RegKeyExists64 = True
End If
End Function

No comments: