How to obtain PackageIDs?
While trying to follow the “How to Create a Package” example, I notice that it does not provide you with the PackageID. You need the PackageID to add programs to a package and the example within the SDK does not show you how to do this in VB.NET (VS 2008). After I digging deeper, I found the example for creating a package with a PDF, “How to Create a Package by Using a Package Definition File Template“
Following this example with the SDK, I modified the original example code to the following, however this does not give me the PackageID (tmp,tmp2,tmp3,tmp4) So how can I get the package ID, so that a program can be created?
Function CreatePackage(ByVal connection, ByVal newPackageName, ByVal newPackageDescription, ByVal newPackageSourceFlag, ByVal newPackageSourcePath)
Dim newpackage
Dim tmp
Dim tmp2
Dim tmp3
Dim tmp4
' Create the new package object.
newPackage = connection.Get("SMS_Package").SpawnInstance_
' Populate the new package properties.
newPackage.Name = newPackageName
newPackage.Description = newPackageDescription
newpackage.PkgSourceFlag = newPackageSourceFlag
newpackage.PkgSourcePath = newPackageSourcePath
newpackage.ForcedDisconnectDelay = 5 '5 minutes
newpackage.ForcedDisconnectEnabled = True 'disconnect clients
newpackage.ForcedDisconnectNumRetries = 7 ' 7 retries
newpackage.manufacturer = "SMSUG.ca"
newpackage.Packagetype = PT_R
'newpackage.PreferredAddressType = ADR_LAN(MS_LAN) **** Dig deeper into the SDK for this.
newpackage.priority = 2 'Normal
newpackage.Sharetype = 1 'Common
tmp4 = newpackage.packageid
' Save the package.
tmp = newpackage.Put_()
tmp3 = newpackage.packageid
tmp2 = tmp.Keys("PackageID")
' Output the new package name.
MsgBox("Created package: " & tmp2)
CreatePackage = tmp2
End Function
Answers
Garth, Jim and I looked at this and saw that in the code you sent me you did figure it out correctly. When using the unmanaged WMI interfaces (via CreateObject) you re-get the object by calling the Get command on the Connection object, passing in the path to the newly saved object:
Code SnippetSet newPackage = Connection.Get(newPackage.Path_.Path)I also think that passing in the put_ result will work:
Code SnippetSet newPackage = Connection.Get(newPackage.Put_)
All Replies
After you do the Put you need to call the Get method to get the package ID.lcacciatore wrote: After you do the Put you need to call the Get method to get the package ID.
I don't see any example of a Get in the SDK and I tried
newpackage.Put_()
newpackage.get_("packageid")and
newpackage.Put_()
newpackage.get_()
tmp3 = newpackage.packageidBoth will produce the same error.
Public member 'get_' on type 'SWbemObjectEx' not found.
What am I missing?
The code I have is for C#.
IResultObject
newPackage = SMSWMI.CreateInstance("SMS_Package");newPackage[
"Name"].StringValue = package.Name;newPackage.Put();
newPackage.Get();
string newPackageID = newPackage[
"PackageID"].StringValue;
There should be a Get method in VBscript.
| lcacciatore wrote: | |
|
Well there might be a "Get" but.... If there is one it is not well documented and the code above does not work correctly. Hence why I'm looking for more information.
Garth, Jim and I looked at this and saw that in the code you sent me you did figure it out correctly. When using the unmanaged WMI interfaces (via CreateObject) you re-get the object by calling the Get command on the Connection object, passing in the path to the newly saved object:
I also think that passing in the put_ result will work:
Set newPackage = Connection.Get(newPackage.Put_)
It's strange, when I run the examples from SMS Scripting Guide in VBS locally - the Get() returns a PackageID - it was only when I was editing the VB for ASP/VBscript that I noticed it did not return PackageID. This continued to perplex me until I looked at the examples for SWDCreatePDFPackage subroutine - it was the packageID = newPackagePath.Keys("PackageID") that made all of the difference for me (keep in mind this was only validated using ASP/VBscript:)
Sub CreatePackageInFolder(connection, newPackageName, newPackageDescription, newPackageSourceFlag, newPackageSourcePath)
' Create the new package object.
Set newPackage = connection.Get("SMS_Package").SpawnInstance_
' Populate the new package properties.
newPackage.Name = newPackageName
newPackage.Description = newPackageDescription
newPackage.PkgSourceFlag = newPackageSourceFlag
newPackage.PkgSourcePath = newPackageSourcePath
' Save the package.
Set newPackagePath = newPackage.Put_
newPackageID = newPackagePath.Keys("PackageID")
' Output the new package name.
Response.Write("Package ID was: " & newPackageID)
strExistingPackageID = newPackageID
'get Folder Identifier
For Each objFolder in connection.InstancesOf("SMS_ObjectContainerNode")
if objFolder.Name=strConsoleFolder and objFolder.ObjectType=2 Then
FolderIdentifier=objFolder.ContainerNodeID
End If
Next
'move the package to specific folder
Set objNewConsoleFolderItem = connection.Get _
("SMS_ObjectContainerItem").SpawnInstance_()
objNewConsoleFolderItem.InstanceKey = newPackageID
objNewConsoleFolderItem.ObjectType=2 ' Package Node.
objNewConsoleFolderItem.ContainerNodeID = FolderIdentifier 'Container
objNewConsoleFolderItem.Put_
Response.Write "Package Moved to Folder:" & FolderIdentifier
End Sub
VOILA: Packages in Folders under Admin GUI
- Proposed As Answer byMC West Sunday, October 25, 2009 6:47 AM

