/build/static/layout/Breadcrumb_cap_w.png

add parameter to remote file execution command

I'm trying to write a script to remotely uninstall the Microsoft SCCM client.

The uninstall command itself is "C:\WINDOWS\system32\ccmsetup\ccmsetup.exe /uninstall"

I used a similar script to remotely install the client, but I'm having trouble getting the uninstall command to work, I'm guessing because of the presence of the /uninstall parameter. Not sure how to get the script to accept that parameter.

Here's the line that I've been messing with that contains the actual uninstall command:

strCommand = "\\" & strCompName & "\C$\WINDOWS\system32\ccmsetup\ccmsetup.exe" & " /" & "uninstall"


I've tried as many iterations of that line as I could think up but still haven't had success getting the script to run. I should clarify that: the script returns a success message, but what happens on the remote PC is that ccmsetup.exe runs, so it's like the uninstall parameter is being ignored.

Here's the script in its entirety (it's only a test version--for instance, I still need to add code that verifies the PC name provided is an actual PC on the network, etc.):


Option Explicit
Dim objFSO, objReg, objPing, objWMIService, objScheduledJob, objSWbemDateTime
Dim strCompName, strKeyPath, strValueName, strValue, strFileName, strCommand
Dim TraceResult, Addresses
Dim errReturn
Dim intJobID
' constants for the Scheduled Job we'll trigger to do the install on the remote PC
Const INTERVAL = "n"
Const MINUTES = 1
' constant for use with querying registry on remote PC
Const HKEY_LOCAL_MACHINE = &H80000002

' //////////////////////
' INPUT BOX FOR P TAG (PC ID #)
' //////////////////////
'Set objNetwork = CreateObject("Wscript.Network")
Set objFSO = CreateObject("Wscript.Network")
' display an InputBox; user enters a P tag
strCompName = InputBox _
("Enter P tag or PC ID number:", _
"P tag - SCCM uninstall")
' if no P tag entered, cancel the program
strCompName = Trim(strCompName)
If strCompName = "" Then
Wscript.Quit
End If

' Check if remote PC has SCCM installed
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{CE6A85D8-D6B9-479A-9FE9-A06E56881E61}"
strValueName = "DisplayName"
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strCompName & "\root\default:StdRegProv")
objReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
If strValue = "Configuration Manager Client" Then
' remote PC has SCCM client, so initiate uninstall
strCommand = "\\" & strCompName & "\C$\WINDOWS\system32\ccmsetup\ccmsetup.exe" & " /" & "uninstall"
Set objWMIService = GetObject("winmgmts:\\" & strCompName & "\root\cimv2")
Set objScheduledJob = objWMIService.Get("Win32_ScheduledJob")
Set objSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")
objSWbemDateTime.SetVarDate(DateAdd(INTERVAL, MINUTES, Now()))
errReturn = objScheduledJob.Create(strCommand, objSWbemDateTime.Value, False, 0, 0, True, intJobID)
If errReturn = 0 Then
WScript.Echo strCompName & vbTab & "Initiating SCCM uninstall in 1 minute."
Else
WScript.Echo strCompName & vbTab & "ERROR. SCCM could not be uninstalled."
End If
End If

0 Comments   [ + ] Show comments

Answers (3)

Posted by: Jsaylor 14 years ago
Second Degree Blue Belt
1
Is there a reason you're using the scheduledjob class, as opposed to win32_process?

Asides from that, your path appears to be written as a remote path, but WMI runs the command as though it were locally created. For instance, instead of writing for the admin share at \\COMPUTER\c$\program.exe, you should write it simply as "c:\program.exe." Therefore, your win32_process command should look like:

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strCompName & "\root\cimv2")

Set objProcess = objWMIService.Get("Win32_Process")

objProcess.Create "c:\windows\system32\ccmsetup\ccmsetup.exe /uninstall", Null, objConfig, intProcessID


Try that out and see how horribly it fails!
Posted by: anonymous_9363 14 years ago
Red Belt
1
I suspect the OP is using a Scheduled Task in order to delay the execution.

@OP, I'd change your test for the presence of the client by simply checking for the presence of the file you're going to execute. As it stands, your script will only uninstall whichever version of the client has the ProductCode you're currently testing for. At the next release, your script will require editing. By checking for the EXE, it'll uninstall any flavour which uses CCMSETUP.EXE.
Posted by: RonW 14 years ago
Green Belt
0
Good points, all. I realized I don't really need to delay execution, and I was only using the ScheduledJob class because, well, because that's the first example I found that I got to work--I'm using similar code in another script for installing the client remotely.

This is the code that works for me:
strComputer = "[name of PC]"
strCommand = "c:\windows\system32\ccmsetup\ccmsetup.exe /uninstall"
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objProcess = objWMIService.Get("Win32_Process")
errReturn = objProcess.Create(strCommand, null, null, intProcessID)
If errReturn = 0 Then
WScript.Echo "Uninstalling SCCM initiated, with a process ID: " & intProcessID
Else
WScript.Echo "SCCM could not be uninstalled due to error: " & errReturn
End If

Still need to build in some checks and error handling that I can pull from my script that installs the client. Thanks for the suggestions!
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ