Sponsored Links

Have you ever wanted to uninstall software remotely across your domain?
Well, this script can do just that!
All you will need is a couple of pieces of information and you can uninstall an application silently.

Copy and paste the following text into notepad and save it as a .vbs file.
 
----------COPY EVERYTHING BELOW THIS LINE----------

'This script will enable Telnet and uninstall an application remotly.
'By Cheyenne Harden 4-28-06
'____________________________________________________________

 

Dim oWS, oWMI, oService, cServices
Dim sService, result, sComputer, sState
intSleepMed = 8000

' sState can be "Automatic", "Manual", or "Disabled"
Const title = "Service State Tool."
Set oWS = CreateObject("Wscript.Shell")
'telnet is the service used to connect remotely
sService = "Tlntsvr"


'This inputbox will prompt you for a computer name or IP
sComputer = inputbox("Enter Target computer's IP or name.",title,".")
If sComputer = "" then
 msgbox "Script halted. No changes were made.", vbInformation, title
 wscript.quit
End If


'This input box will allow you to set a service to auto, man, or disable
Do
sState = inputbox("Enter state to set the service." & vbCrlf &_
 "Values can be automatic, manual, Or disabled.", title, "automatic")
Select Case lcase(sState)
 Case ""
 msgbox "Script halted. No changes were made.", vbInformation, title
 wscript.quit

 Case "automatic", "manual", "disabled"
 
 Case Else
 

msgbox "Values can be automatic, manual, or disabled.", vbExclamation, title
End Select

Loop until lcase(sState) = "automatic" Or lcase(sState) = "manual" Or lcase(sState) = "disabled"
' Can quit from here
result = MsgBox ("The " & sService & " service will be set to " & sState & ". Are you sure?", vbQuestion + vbYesno, title)
If result = vbNo Then
 Msgbox "Script halted. No changes were made.", vbInformation, title
 wscript.quit
End If

'This part of the script uses your credentials to access the remote computer
'You should be an admin to use this

Set oWMI = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")


' See if the displayname or name exists
Set cServices = oWMI.ExecQuery _
    ("Select * from Win32_Service Where Name = '" & sService & "' or displayName = '" & sService & "'")
If cServices.count > 0 Then
 For Each oService In cServices
  oService.StartService()
' Give service 8 seconds to start
   wscript.Sleep intSleepMed
  oService.ChangeStartMode(sState)
If oService.started = "False" Then
 
 Msgbox "The service is starting"
 wscript.Sleep intSleepMed
End If
  Msgbox "The " & sService & " service on " & sComputer & _
  " is now " & sState & ".", vbInformation, title
 Next

'____________________________________________________________
'This part of the script will find the uninstall string.
'____________________________________________________________


Const HKEY_LOCAL_MACHINE = &H80000002


Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    sComputer & "\root\default:StdRegProv")

'strUninstall is the name of the key path
'Ex:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Ethereal
'Ethereal is what you need to type in the input box
strUninstall = InputBox ("Enter the string to be uninstalled")
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & strUninstall
strValueName = "UninstallString"
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
Wscript.Echo "Uninstall Value: " & strValue

 

'____________________________________________________________
'This part of the script will Telnet into a computer and uninstall an application.
'____________________________________________________________

 

Dim strInput

Dim objShell, intShortSleep, intLongSleep, intVeryLongSleep, intXLSleep
Set objShell = CreateObject("WScript.Shell")


Do

     If sComputer <> "" Then
     strInput = True
     End if
Loop until strInput = True


' Values set here
intShortSleep = 1000
intLongSleep = 2000
intVeryLongSleep = 4000
intXLSleep = 8000
var3 = "sc config Tlntsvr start= disabled"
var4 = "net stop Tlntsvr"
strSwitch = inputbox("Enter any needed Switches.",title,"")


wscript.Sleep 6000
' Cmd prompt opened
objShell.Run "cmd"
Wscript.Sleep intShortSleep

' Send change directory command
objShell.SendKeys "cd c:\"
Wscript.Sleep intShortSleep
objShell.SendKeys "{Enter}"
Wscript.Sleep intLongSleep

' Send telnet command
objShell.SendKeys "telnet " & sComputer
Wscript.Sleep intShortSleep
objShell.SendKeys "{Enter}"
Wscript.Sleep intXLSleep

'Uninstall Application
objShell.SendKeys strValue & " " & strSwitch
Wscript.Sleep intVeryLongSleep
objShell.SendKeys "{Enter}"

' Set Service to Disable
objShell.SendKeys var3
Wscript.Sleep intLongSleep
objShell.SendKeys "{Enter}"

'Exit Telnet
objShell.SendKeys var4
Wscript.Sleep intShortSleep
objShell.SendKeys "{Enter}"


End If
WScript.Echo "Your application has been uninstalled!"
WScript.Quit

----------COPY EVERYTHING ABOVE THIS LINE----------

 

Here is what you need to know to run this script:
1. Name of the computer you are targeting

2. Name of the uninstall key EX.(If you wanted to uninstall Ethereal you will use this Regkey  HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Ethereal )
"Ethereal" is what you would type in without the quotes.

3. Any switches (Ex. For Ethereal to uninstall silently use a  /S).

*** Warning, Do not click on other application while running this script because of VBS send keys function will enter commands to the application that has focus.

This information is provided "AS IS" with no warranty expressed or implied.