Ask a questionAsk a question
 

AnswerHow to obtain PackageIDs?

  • Friday, June 13, 2008 4:51 PMGarth JonesMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    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

  • Tuesday, June 17, 2008 6:08 PMAndy De GeorgeMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

     

    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 Snippet
    Set newPackage = Connection.Get(newPackage.Path_.Path)

     

     

     

    I also think that passing in the put_ result will work:

     

    Code Snippet

    Set newPackage = Connection.Get(newPackage.Put_)

     

     

All Replies

  • Friday, June 13, 2008 5:10 PMlcacciatore Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    After you do the Put you need to call the Get method to get the package ID.
  • Friday, June 13, 2008 5:40 PMGarth JonesMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
     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.packageid

     

    Both will produce the same error.

     

    Public member 'get_' on type 'SWbemObjectEx' not found.

     

    What am I missing?
  • Friday, June 13, 2008 7:14 PMlcacciatore Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    The code I have is for C#.

     

    Code Snippet

    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.
  • Friday, June 13, 2008 8:17 PMGarth JonesMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
     lcacciatore wrote:

    The code I have is for C#.

     

    There should be a Get method in VBscript.

     

    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.

  • Tuesday, June 17, 2008 6:08 PMAndy De GeorgeMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

     

    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 Snippet
    Set newPackage = Connection.Get(newPackage.Path_.Path)

     

     

     

    I also think that passing in the put_ result will work:

     

    Code Snippet

    Set newPackage = Connection.Get(newPackage.Put_)

     

     

  • Saturday, October 24, 2009 9:58 PMMC West Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Proposed Answer

    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
    •