Question : VBscript for psexec

Hi All
I am trying to use psexec in a login script that will uninstall autocad on some machines
I can make the scripting work manually on a single workstation using a cmd prompt with below cmd

psexec \\ct1.xxxxxxx.local -u ct1\administrator -p xxxxx MsiExec.exe /norestart /q/x{5783F2D7-7001-0409-0002-0060B0CE6BBA} REMOVE=ALL

The problem I am having is that we have 3 different versions that spread out over 50 machines so I would like to use a login script that uses reg read to see if 1 of 3 reg entries is there and if so uninstall
This is the script I have been trying to make work.

Option Explicit

If KeyExists("HKLM\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\{5783F2D7-7001-0409-0002-0060B0CE6BBA}\") Then
    psexec.exe  "MsiExec.exe /norestart /q/x{5783F2D7-7001-0409-0002-0060B0CE6BBA} REMOVE=ALL"
Else

If KeyExists("HKLM\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\{5783F2D7-4001-0409-0002-0060B0CE6BBA}\") Then
    psexec "MsiExec.exe /norestart /q/x{5783F2D7-4001-0409-0002-0060B0CE6BBA} REMOVE=ALL"
Else
If KeyExists("HKLM\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\{5783F2D7-5001-0409-0002-0060B0CE6BBA}\") Then
    psexec "MsiExec.exe /norestart /q/x{5783F2D7-5001-0409-0002-0060B0CE6BBA} REMOVE=ALL"


Function KeyExists(key)
    Dim objShell
    On Error Resume Next
    Set objShell = CreateObject("WScript.Shell")
        objShell.RegRead (key)
    Set objShell = Nothing
    If Err = 0 Then KeyExists = True
End If
End Function


I am not sure if I need all those lines or even if they are correct
TIA

WP

Answer : VBscript for psexec

hey try this
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
Option Explicit
Dim objShell, objNetwork
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")


If KeyExists("HKLM\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\{5783F2D7-7001-0409-0002-0060B0CE6BBA}\") Then
	objShell.Run "psexec -accepteula -e -u sa\super11 -p mine$22 \\" & objNetwork.ComputerName & " MsiExec.exe /norestart /q/x{5783F2D7-7001-0409-0002-0060B0CE6BBA} REMOVE=ALL", 1, True
ElseIf KeyExists("HKLM\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\{5783F2D7-4001-0409-0002-0060B0CE6BBA}\") Then
	objShell.Run "psexec -accepteula -e -u sa\super11 -p mine$22 \\" & objNetwork.ComputerName & " MsiExec.exe /norestart /q/x{5783F2D7-4001-0409-0002-0060B0CE6BBA} REMOVE=ALL", 1, True
ElseIf KeyExists("HKLM\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL\{5783F2D7-5001-0409-0002-0060B0CE6BBA}\") Then
	objShell.Run "psexec -accepteula -e -u sa\super11 -p mine$22 \\" & objNetwork.ComputerName & " MsiExec.exe /norestart /q/x{5783F2D7-5001-0409-0002-0060B0CE6BBA} REMOVE=ALL", 1, True
End If

		
Function KeyExists(key)
	Dim objShell
	Set objShell = CreateObject("WScript.Shell")
	On Error Resume Next
	objShell.RegRead(key)
	If Err.number <> 0 Then 
		KeyExists = False
		Err.Clear
	Else
		KeyExists = True
	End If
End Function

		
Random Solutions  
 
programming4us programming4us