How to Create SMS Package and Program Objects

Published : April 11, 2005

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:

  • The package has no source files (the default).

  • The package has source files, and SMS should obtain them directly from the source path.

  • The package has source files, but SMS should make and use a compressed copy of them.

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.

On This Page

Compiling the Code
See Also


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.gif  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
'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
'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"
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"
wscript.echo "Created program " +ProgramName

Compiling the Code

  • Requires Windows 2000 Server SP2 or later.

  • Requires an SMS 2003 site server.

See Also


How to Create an SMS Advertisement

How to Create, Modify, and Delete SMS Objects

How to Modify an SMS Advertisement