Here you go. Save the script below in a .vbs file, which you can then
run from the command-line by typing:
cscript whateverFileName.vbs
'=============== SCRIPT STARTS HERE ================================
Option Explicit
'-----------------------------------------------------
' 1. Execute commands
'-----------------------------------------------------
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
Dim oExec1, oExec2
Set oExec1 = WshShell.Exec("C:\Program Files\Altiris\Altiris Agent" &_
"\aexagentutil.exe /uninstallagents /clean")
Do While oExec1.Status = 0
WScript.Sleep 100
Loop
Set oExec2 = WshShell.Exec("C:\Program Files\Altiris" &_
"\Carbon Copy\unsetup.exe -n -q")
Do While oExec2.Status = 0
WScript.Sleep 100
Loop
'-----------------------------------------------------
' 2. Delete main directory
'-----------------------------------------------------
Dim commandString1
commandString1 = "%comspec% /c rmdir /s /q ""C:\Program Files\" &_
"Altiris\Altiris Agent"" "
'wscript.echo commandString1
WshShell.Run commandString1
'-----------------------------------------------------
' 3a. Delete registry entries
'-----------------------------------------------------
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_CURRENT_CONFIG = &H80000005
Const HKEY_DYN_DATA = &H80000006
Dim RegHive
'Select registry hive constant from above list.
RegHive = HKEY_LOCAL_MACHINE
'Call helper subroutine to delete registry keys
DelKey RegHive, "Software\Altiris\Altiris Agent"
DelKey RegHive, "Software\Altiris\eXpress"
DelKey RegHive, "Software\Altiris\Scheduler"
DelKey RegHive, "Software\Altiris\APackageStub"
DelKey RegHive, "Software\Altiris\AppID\{5E038245-CF81-44BE-8018-9A2981B9DC9B}"
'-------------------------------------------------------------
'3b. Search for registry entries that match criteria under
' Software\Classes key, and delete matches
'-------------------------------------------------------------
Dim strComputer, oReg, strKeyPath, arrSubKeys, subKey
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
strKeyPath = "Software\Classes"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
If IsArray(arrSubKeys) Then
'Check if Altiris occurs in string at the very beginning (position is 1-based)
For Each subKey In arrSubKeys
If InStr(subKey,"Altiris") = 1 Then
'Call helper subroutine to delete registry entry
DelKey HKEY_LOCAL_MACHINE, strKeyPath + "\" + subKey
End if
Next
End If
'-------------------------------------------------------------
'4. Delete *AeX* files in Windows directory
'-------------------------------------------------------------
Dim fso, winFolder, commandString2
Set fso = CreateObject("Scripting.FileSystemObject")
Set winFolder = fso.GetSpecialFolder(0)
commandString2 = "%comspec% /c C: & cd\ & cd " &_
winFolder.Name &_
" & del /q *AeX*"
'wscript.echo commandString2
WshShell.Run commandString2
'------------------------------------------------------------------------
' Helper method to recursively delete all subkeys of a key and then
' delete the key itself. This is needed because you get an error if
' you try to delete a key that contains subkeys.
' Copied from: http://www.codecomments.com/archive300-2004-5-198638.html
'------------------------------------------------------------------------
Sub DelKey(RegRoot, sPath)
Dim sKeys
Dim SubKeyCount
Dim objRegistry
Dim lRC
Dim lRC2
Dim Key
Set objRegistry = GetObject("winmgmts:root\default:StdRegProv")
lRC = objRegistry.EnumKey(RegRoot, sPath, sKeys)
If IsArray(sKeys) Then
for each Key in sKeys
DelKey RegRoot, sPath & "\" & Key
next
End If
lRC2 = objRegistry.DeleteKey(RegRoot, sPath)
If (lRC2 <> 0) Then
wscript.echo "Error deleting key " & sPath
End If
End Sub
'============================= SCRIPT ENDS HERE ===================
Remarks:
1. The script probably isn't perfect, but hopefully it's something you
can work from.
2. No error handling is done, so if, for example, the uninstaller
program doesn't exist, it will fail trying to execute it and the rest
of the script won't execute.
3. It assumes the place where the user installed the program is
"C:\Program Files\...", when the user possibly could have chosen somewhere else.
4. It is very dangerous to delete *AeX* as you are wanting to do. You
should know exactly what files you need to delete and delete them one
by one. What if a critical windows component (or other 3rd party
component) exists called "winaexec.exe" or something? You never know
what might contain a string that you think is unique to your
application files.
Here are some links to helpful pages for implementing the steps:
1,4. http://msdn.microsoft.com/library/en-us/script56/html/wslrfexecmethod.asp
2. http://www.computerperformance.co.uk/ezine/ezine80.htm
3. http://www.codecomments.com/archive300-2004-5-198638.html |