Setting ConfigMgr 2007 App-V Program OS Restrictions - Sample Script


Below is vbscript that sets designated OS restrictions for all App-V packages within a ConfigMgr 2007 folder (since this cannot be done in the GUI). It's useful when using ConfigMgr user-based targetting to ensure App-V packages are only downloaded to the designated operating system(s).

ConfigMgr 2012 allows setting this in the GUI.

Note: This script should be saved as a .vbs file and run with administrative permissions on the ConfigMgr server. Before running, the folderID of the planned targetting folder needs to be determined (which can be done by a referenced script). Also note, the script below suppresses the countdown dialog.

Dim StrSMSServer, strPackageID, strProgramName, strFolderNodeID
Dim objLocator, objSCCM, objProgram, objPrograms, Providers, Provider
Dim tempSupportedPlatform, tempSupportedPlatform2, tempSupportedPlatformsArray
Dim colObjectContainerItems
Dim item

strSMSServer = "."
strFolderNodeID = "<folderID - fromother.vbs>"
strProgramName = "[Virtual application]"

Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objSCCM = objLocator.ConnectServer(strSMSServer, "root\sms")
Set Providers = objSCCM.ExecQuery("SELECT * From SMS_ProviderLocation WHERE ProviderForLocalSite = true")
For Each Provider in Providers
  If Provider.ProviderForLocalSite = True Then
    Set objSCCM = objLocator.ConnectServer(Provider.Machine, "root\sms\site_" & Provider.SiteCode)
  End If
Next

Set colObjectContainerItems=objSCCM.Execquery("select * from sms_objectcontaineritem where objecttype=2 and ContainerNodeId='" & strFolderNodeID & "'")
For each item in colObjectContainerItems
  WScript.Echo item.InstanceKey
  Set objPrograms = objSCCM.ExecQuery("Select * from SMS_Program where PackageID='" & item.InstanceKey & "' and ProgramName='" & strProgramName & "'")
  For each objProgram in objPrograms

    If (objProgram.ProgramFlags and 1024) = 0 then
     WScript.Echo "Suppress Countdown Flag Not Present - Setting Flag"
     WScript.Echo "Adding 0x00000400 (COUNTDOWN. The countdown dialog is not displayed)"
     objProgram.ProgramFlags = objProgram.ProgramFlags + 1024
    Else
      WScript.Echo "Flag Already Set"
    End If     

    If (objProgram.ProgramFlags and 134217728) = 134217728 then
     WScript.Echo "Override platform support enabled - Removing Flag"
     WScript.Echo "Removing 0x08000000 (Override check for platform support) to allow OS restriction to be set"
     objProgram.ProgramFlags = objProgram.ProgramFlags - 134217728
    Else
      WScript.Echo "Flag Already Set"
    End If

    WScript.Echo "Sets OS Values"
 
    Set tempSupportedPlatform = objSCCM.Get("SMS_OS_Details").SpawnInstance_
                    
    ' Populate tempSupportedPlatform values.   
    tempSupportedPlatform.MaxVersion = "6.10.9999.9999"
    tempSupportedPlatform.MinVersion = "6.10.0000.0"
    tempSupportedPlatform.Name       = "Win NT"
    tempSupportedPlatform.Platform   = "x64"
 
    ' Use the existing array to set datatype
    tempSupportedPlatformsArray = objProgram.SupportedOperatingSystems  
           
    ' Add the new supported platform values (object) to the temporary array.
    ReDim tempSupportedPlatformsArray (0)
    Set tempSupportedPlatformsArray(0) = tempSupportedPlatform

    ' Replace the SupportedOperatingSystems object array with the new array.
    objProgram.SupportedOperatingSystems = tempSupportedPlatformsArray

    WScript.Echo "Set flags and OS values"
    objProgram.Put_

  Next
Next

 

References:
Script to find folder ID: http://blog-en.netvnext.com/2011/03/list-of-packages-in-sccm-folder.html#!/2011/03/list-of-packages-in-sccm-folder.html
List of OS values (note: I386 is case-sensitive): http://social.technet.microsoft.com/Forums/en-US/configmgrswdist/thread/43e5e010-d14d-4907-be79-c63bea79d7ae/
Program Flags Reference: http://msdn.microsoft.com/en-us/library/cc143360.aspx
MSDN setting OS restriction reference: http://msdn.microsoft.com/en-us/library/cc144942.aspx
Set OS restrictions: http://techpppp.blogspot.com/2010/09/sccm-converting-programs-to-windows-7.html

Note: No warranty or support is implied with the use of the scripts discussed in this article.

Comments (0)

Skip to main content