Pages

Monday, August 16, 2010

Uninstalling AutoCAD Civil 3D 2011 with SCCM 2007

As promised, here is part 2 of my previous post about removing AutoCAD 2011 products using System Center Configuration Manager (SCCM).  I use a script to herd all the 3-legged cats together and remove them at once, silently.  Kind of like stealth kitty extraction.  Or something like that.

BEGIN VBSCRIPT…

'****************************************************************
' Filename..: uninstall_2011_civil3d.vbs
' Author....: David M. Stein
' Date......: 08/16/2010
' Purpose...: uninstall autocad civil 3d 2011
' SQL.......: N/A
'****************************************************************
Option Explicit

wscript.echo "info: initialized " & Now
wscript.echo "info: script executed from " & wscript.ScriptFullName

Dim oShell, oFSO, progfiles, sysdrive, counter : counter = 0

Set oShell = CreateObject("Wscript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")

progfiles = oShell.ExpandEnvironmentStrings("%programfiles%")
sysdrive = oShell.ExpandEnvironmentStrings("%systemdrive%")

wscript.echo "info: product installation was found."

CleanApp "DirectX 9.0c for Civil 3D 2011", "{0B8F69E3-5983-4B2B-B464-5D833C76773D}"

CleanApp "Autodesk Material Library 2011", "{9DEABCB6-B759-4D52-92F8-51B34A2B4D40}"

CleanApp "Autodesk Material Library 2011 Base Image library", "{CD1E078C-A6B9-47DA-B035-6365C85C7832}"

CleanApp "AutoCAD Civil 3D 2011", "{5783F2D7-9000-0409-0002-0060B0CE6BBA}"

CleanApp "AutoCAD Civil 3D 2011 Language Pack - English", "{5783F2D7-9000-0409-1002-0060B0CE6BBA}"

CleanApp "Autodesk Design Review 2011", "{8D20B4D7-3422-4099-9332-39F27E617A6F}"

CleanApp "FARO LS 1.1.406.58", "{951B0F30-9F1A-4BF6-B3DA-99EB0E917B1C}"

If counter > 0 Then
CleanFolder progfiles & "\Autodesk\AutoCAD Civil 3D 2011"
CleanFolder progfiles & "\Autodesk\LandXML Reporting 8"
CleanFolder sysdrive & "\Civil 3D Project Templates"
CleanFolder sysdrive & "\Civil 3D Projects"
End If

wscript.echo "info: " & counter & " applications removed"
wscript.echo "info: completed at " & Now

'----------------------------------------------------------------
' function: check if reg key exists under Uninstall tree
'----------------------------------------------------------------

Function IsInstalled(keyname)
Dim basekey
basekey = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
If RegKeyExists(basekey & keyname & "\") Then
IsInstalled = True
End If
End Function

'----------------------------------------------------------------
' function: return True if registry key exists
' EXAMPLE: If RegKeyExists("HKLM\Sofwtare\ACME\TestKey\Value1") Then
'----------------------------------------------------------------

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: run MSIEXEC to uninstall a GUID-based app
'----------------------------------------------------------------

Sub Uninstall(key)
oShell.Run "msiexec.exe /x " & key & " /qn", 7, True
End Sub

'----------------------------------------------------------------
' function: macro to check for app and remove it
'----------------------------------------------------------------

Sub CleanApp(name, keyname)
wscript.echo "info: searching for " & name
If IsInstalled(keyname) Then
wscript.echo "info: removing " & name
Uninstall keyname
counter = counter + 1
Else
wscript.echo "info: " & name & " is not installed"
End If
End Sub

'----------------------------------------------------------------
' function:
'----------------------------------------------------------------

Sub CleanFolder(path)
Dim retval
If oFSO.FolderExists(path) Then
On Error Resume Next
retval = oFSO.DeleteFolder(path, True)
If err.Number = 0 Then
wscript.echo "info: folder deleted = " & path
Else
wscript.echo "warn: folder not deleted = " & path
End If
Else
wscript.echo "warn: folder not found = " & path
End If
End Sub

'----------------------------------------------------------------
' function:
'----------------------------------------------------------------

Function ScriptPath()
ScriptPath = Replace(wscript.ScriptFullName, _
"\" & wscript.ScriptName, "")
End Function

No comments:

Post a Comment