Sign in to follow this  
Followers 0
Kovacic

System Center Configuration Manager (SCCM) Trigger download

8 posts in this topic

Greetings, I am trying to make a small program that, when launched on a client computer, initiates an SCCM software install. I have done alot of searching and code testing and found the _SCCM UDF does not do what I need, that is more of a server admin tool. 

 

The tool I'm looking to make will launch installs for pre specified software packages that do not require approval in SCCM. I tried using Fiddler to grab the button push string, but it uses session cookies and all types of extra auth strings. Has anyone found a way to do this?

This is my test for connecting to the SCCM Server which does work..

 

#include <Array.au3>
#include <_SCCM.au3>
$oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
$oConfigMgr = ObjCreate("Microsoft.SMS.Client")
If Not @error Then $sServer = $oConfigMgr.GetCurrentManagementPoint
$SCode = "MySite"
$sPC = @ComputerName
Local $oLocator = ObjCreate("WbemScripting.SWbemLocator")
If IsObj($oLocator) Then
    $__goSMS = $oLocator.ConnectServer($sServer, "root\sms\site_CFG")
    If @error Then
        MsgBox(0, "Debug", "Error")
    Else
        MsgBox(0, "Debug", "It worked.")
    EndIf
EndIf
Func MyErrFunc()
    MsgBox(0, "AutoItCOM", "We intercepted a COM Error !" & @CRLF & @CRLF & _
            "err.description is: " & @TAB & $oMyError.description & @CRLF & _
            "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
            "err.number is: " & @TAB & Hex($oMyError.number, 8) & @CRLF & _
            "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
            "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
            "err.source is: " & @TAB & $oMyError.source & @CRLF & _
            "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
            "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            )
    Local $err = $oMyError.number
    If $err = 0 Then $err = -1
    $g_eventerror = $err ; to check for after this function returns
EndFunc   ;==>MyErrFunc

Thanks!!!!!!!!

 

 


C0d3 is P0etry( ͡° ͜ʖ ͡°)

Share this post


Link to post
Share on other sites



@Kovacic, you are right my SCCM UDF won't do what you're after. My question would be why you would want to initiate a push from the client rather than creating a collection and putting that machine in the collection, then using the Config Manager to pull it down. Just curious what the driver is, as this seems completely backward from normal use; In all my time administering SCCM and SMS I've never come across a need to do it this way. Are you perhaps meaning a package that has been set to Available, and not Required?

1 person likes this

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

You are absolutely correct, it is contrary to best practice.. However I am making a post profiler for end users, so what it will ultimately do is, when we run the backup on their old computer, it will detect what software they have installed and make a CSV of that list (that part is already done). The restore (post profile) portion will look at that list, and only install software they already have, even though they may have been approved for other software. I have this scripted out for the most part in pieces because only I was using it, but the company I work for says they have a need for me to beautify it and package it for release. The ultimate goal is to have this as simple as possible for an end user to operate with very few options. I don't want to send them to the SCCM web console to choose their software, I just want to auto push the stuff they already had.. That's what I am hoping to do anyways...

 

Thanks!!


C0d3 is P0etry( ͡° ͜ʖ ͡°)

Share this post


Link to post
Share on other sites

My one and only bump... Hoping someone has been able to crack the SCCM mysteries :)


C0d3 is P0etry( ͡° ͜ʖ ͡°)

Share this post


Link to post
Share on other sites

Have you tried Powershell?  I have not attempted this specific task but i think the mechanisms are there.

 


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

In re-reading your explanation, I think you could do something with the SCCM UDF: If you used _SCCM_ListCollectionsForPC to gather all the collections they are in, you could then use _SCCM_AddToCollection to put the new machine in those same collections.

I guess I don't understand the "install only the software they already have, even if they have been approved for other software" bit. It sounds like, rather than a list of collections on the old machine, you want to pull a list of applications installed via WMI, and only put the new machine into those collections. Is that closer to what you're thinking?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

In re-reading your explanation, I think you could do something with the SCCM UDF: If you used _SCCM_ListCollectionsForPC to gather all the collections they are in, you could then use _SCCM_AddToCollection to put the new machine in those same collections.

I guess I don't understand the "install only the software they already have, even if they have been approved for other software" bit. It sounds like, rather than a list of collections on the old machine, you want to pull a list of applications installed via WMI, and only put the new machine into those collections. Is that closer to what you're thinking?

Yes, thats about right, only WMI is kind of slow, so I used this:

Func _InstalledSoftware($sComputerName = @ComputerName) 
    $iInstalledAppsCount = 1
    $sInstalledAppsLog =  $ProfilePath & "\Installed Software x64.csv"
    $hInstalledAppsLogFile = FileOpen($sInstalledAppsLog, 1) ;Output to a CSV file.
    While 1
        $sSubKey = RegEnumKey("\\" & $sComputerName & "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", $iInstalledAppsCount)
        Switch @error
            Case 1, 2, 3
                ;
            Case -1
                ExitLoop
        EndSwitch
        $sDisplayName = RegRead("\\" & $sComputerName & "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $sSubKey, "DisplayName")
        $sDisplayVersion = RegRead("\\" & $sComputerName & "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & $sSubKey, "DisplayVersion")
        If $sDisplayName <> "" Then FileWriteLine($hInstalledAppsLogFile, $sDisplayName & "," & $sDisplayVersion)
        $iInstalledAppsCount += 1
    WEnd
    FileClose($hInstalledAppsLogFile)
    Local $aInstalledApps
    _FileReadToArray($sInstalledAppsLog, $aInstalledApps)
;~  _ArrayDisplay($aInstalledApps) ;For Testing.
    _ArraySort($aInstalledApps, 0, 1)
;~  _ArrayDisplay($aInstalledApps) ;For Testing.
    _FileWriteFromArray($sInstalledAppsLog, $aInstalledApps, 1)
    _FileWriteToLine($sInstalledAppsLog, 1, "Program Name, Program Version") ;CSV file column headers.
    Return 1
EndFunc

 


C0d3 is P0etry( ͡° ͜ʖ ͡°)

Share this post


Link to post
Share on other sites

Have you tried Powershell?  I have not attempted this specific task but i think the mechanisms are there.

 

Checking this out now, thanks!!


C0d3 is P0etry( ͡° ͜ʖ ͡°)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • iamtheky
      By iamtheky
      *Requires that you are a client of SCCM in order for SMS_ to exist/populate
      This is an exercise in formatting data returned from CIM via powershell via Autoit.  Should get you the meat:  name, version, location, installdate, and uninstall string. 
      Short Version:  Grouped by Program
       
      #RequireAdmin #include<Array.au3> $iPid = run("powershell (Get-CimInstance -Namespace root\cimv2\sms -ClassName SMS_InstalledSoftware | fl ProductName,InstallDate,InstalledLocation,ProductVersion,UninstallString | out-string).trim()", "" , @SW_HIDE , 0x2) $sOutput = "" While ProcessExists($iPid) $sOutput &= StdoutRead($iPID) WEnd $aOutput = stringsplit($sOutput, @LF , 2) _ArrayDisplay($aOutput)  
      Long Version: Each Category in its own column, modular pieces.
       
      ;CIMClasses #include<Array.au3> #RequireAdmin $iPid = run("powershell Get-CimInstance -Namespace root\cimv2\sms -ClassName SMS_InstalledSoftware | select ProductName" , "" , @SW_HIDE , 0x2) $sOutput = "" While 1 $sOutput &= StdoutRead($iPID) If @error Then ExitLoop EndIf WEnd $aProductName = stringsplit($sOutput , @CR , 2) ;;;;;------------------------------------------- $iPid = run("powershell Get-CimInstance -Namespace root\cimv2\sms -ClassName SMS_InstalledSoftware | select InstallDate" , "" , @SW_HIDE , 0x2) $sOutput = "" While 1 $sOutput &= StdoutRead($iPID) If @error Then ExitLoop EndIf WEnd $aInstallDate = stringsplit($sOutput , @CR , 2) ;;;;;------------------------------------------- $iPid = run("powershell Get-CimInstance -Namespace root\cimv2\sms -ClassName SMS_InstalledSoftware | select InstalledLocation" , "" , @SW_HIDE , 0x2) $sOutput = "" While 1 $sOutput &= StdoutRead($iPID) If @error Then ExitLoop EndIf WEnd $aInstalledLocation = stringsplit($sOutput , @CR , 2) ;;;;;------------------------------------------- $iPid = run("powershell Get-CimInstance -Namespace root\cimv2\sms -ClassName SMS_InstalledSoftware | select ProductVersion" , "" , @SW_HIDE , 0x2) $sOutput = "" While 1 $sOutput &= StdoutRead($iPID) If @error Then ExitLoop EndIf WEnd $aProductVersion = stringsplit($sOutput , @CR , 2) ;;;;;------------------------------------------- $iPid = run("powershell Get-CimInstance -Namespace root\cimv2\sms -ClassName SMS_InstalledSoftware | select UninstallString" , "" , @SW_HIDE , 0x2) $sOutput = "" While 1 $sOutput &= StdoutRead($iPID) If @error Then ExitLoop EndIf WEnd $aUninstallString = stringsplit($sOutput , @CR , 2) ;;;;;------------------------------------------- Local $aOut[ubound($aProductName)][5] For $i = 0 to ubound($aProductName) - 1 $aOut[$i][0] = $aProductName[$i] $aOut[$i][1] = $aInstallDate[$i] $aOut[$i][2] = $aInstalledLocation[$i] $aOut[$i][3] = $aProductVersion[$i] $aOut[$i][4] = $aUninstallString[$i] Next _ArrayDisplay($aOut , "SMS Installed Software")  
    • stephend
      By stephend
      I hope this isn't too off topic, as there may be other SCCM users out there.  When running a script as the logged on user (not as System) Regread and Regwrite don't work.  I think this is because even though the script is running with only the user's rights it is still running to some extent in the System account - although a message box popped up from a script running in this way does show the correct username for @username.   What I don't understand is why running in the same way Reg.exe does work in reading and writing to the registry as the logged on user - although I find the syntax harder :-).  Does anyone understand why this is or have a workaround to get Regread etc working is this situation?
      Many thanks as always,
      Stephen