Creating a package object (SMS_Package) is the same as creating other SMS objects. The only required property is a name. SMS automatically fills in the details for many properties, including the package identifier, disconnection settings, priority, and action in progress. You can set properties that are significant to the task that your script is meant to accomplish, such as description, package source path, and package source flag.

The PkgSourceFlag property is often important when creating packages and can have only one of the following values:

Creating programs is also straightforward. Programs require a package identifier, program name, and command line. SMS automatically sets some properties, such as program flags. You can set other properties as needed, such as comment, estimated disk space, or run time. You can also set flags for how the program should run on the client.

For more information about creating SMS packages and programs, see the SMS 2003 SDK.

Example

The following example demonstrates how to create a package and associated program. The example creates a package for Notepad.exe, which is presumed to be available in C:\temp.

Note:
If the SMS Administrator console is open in the Packages node when you run this script, you must refresh the view to see the new package and program. Also, if a package with the same name already exists, a new one is created with the same name.
Dim objSWbemLocator
Dim objSWbemServices
Dim ProviderLoc
Dim Location
Dim PackageName
Dim ProgramName
Dim newPackage
Dim newProgram
Dim Package
Dim PackageID
Dim Path

PackageName="PackageName"
ProgramName="ProgramName"
'Connect to provider namespace for local computer.
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objSWbemServices= objSWbemLocator.ConnectServer(".", "root\sms")
Set ProviderLoc = objSWbemServices.InstancesOf("SMS_ProviderLocation")

For Each Location In ProviderLoc
		If Location.ProviderForLocalSite = True Then
			Set objSWbemServices = objSWbemLocator.ConnectServer _
				 (Location.Machine, "root\sms\site_" + Location.SiteCode)
		End If
Next

'Create package.
Set newPackage = objSWbemServices.Get("SMS_Package").SpawnInstance_()
newPackage.Name = PackageName
newPackage.Description = "created by sample script"
newPackage.PkgSourceFlag = 2 
newPackage.PkgSourcePath = "C:\temp"
Path=newPackage.Put_
wscript.echo "Created packge " +PackageName

'Get the automatically assigned package ID.
Set Package=objSWbemServices.Get(Path)
PackageID= Package.PackageID

Set newProgram = objSWbemServices.Get("SMS_Program").SpawnInstance_()
newProgram.ProgramName = ProgramName
newProgram.PackageID = PackageID
newProgram.Comment = "phone the helpdesk for support with this program"
newProgram.CommandLine = "Notepad.exe"
newProgram.Put_
wscript.echo "Created program " +ProgramName

Compiling the Code

  • Requires Windows 2000 Server SP2 or later.

  • Requires an SMS 2003 site server.

See Also