This example runs available programs on SMS Advanced Clients and on SMS Legacy Clients.

The simplest technique on the Advanced Client is to use the Advanced Client COM Automation objects. The UIResourceMgr object supports methods that can be used to execute programs. On the Legacy Client, the standard WMI client classes are used.

The following script runs the program identified by the sPackageName, sPackageID, and sProgramID parameters.

For additional information, see the SMS 2003 SDK.

Example

On Error Resume Next

Dim oUIResource 
Dim sProgramID
Dim sPackageID
Dim sPackageName 
Dim oArgs
Dim objSWbemlocator
Dim objSWbemServices
Dim szNameSpacePath
Dim oProgramObjectSet
Dim oProgramObject
Dim sProgramObjectPath


szNameSpacePath = "root/microsoft/sms/client/swdist"

sPackageName = "Package1"
sPackageID = "99900001"
sProgramID = "Program1"

Set objSWbemlocator = CreateObject("WbemScripting.SWbemLocator.1")
Set objSWbemServices = objSWbemlocator.ConnectServer(".",szNameSpacePath)

If Err.Number <> 0 Then
'Trying to create UIResource--assuming Advanced Client.

Set oUIResource = CreateObject ("UIResource.UIResourceMgr")
If oUIResource Is Nothing Then 
	wscript.quit(2)
End If
'Run the program.
oUIResource.ExecuteProgram sProgramID, sPackageID, TRUE

wscript.echo "Successfully executed program"
wscript.quit (0)

End If

'Get the program index.
Set oProgramObjectSet = _
	oServices.ExecQuery("Select * from CLI_AvailableProgram where ProgramName=""" + sProgramID + """ and sPackageName=""" + sPackageName + """")

'Run each program in the objectset. You might get more programs 
'because key is package name and not package ID.
For Each oProgramObject In oProgramObjectSet 
sProgramObjectPath = oProgramObject.Path_.RelPath

'Call the WbemMethod to run the program now.
oServices.ExecMethod sProgramObjectPath,"RunNow"
Next

'wscript.echo "Successfully executed program".
wscript.quit(0)

Compiling the Code

  • Requires an SMS 2003 Advanced Client.

See Also