Deploy Windows form powershell app using SCCM

This topic contains 5 replies, has 2 voices, and was last updated by Profile photo of David Zemdegs David Zemdegs 5 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #38329
    Profile photo of David Zemdegs
    David Zemdegs
    Participant

    I have an Windows Form exe which I have created using Powershell Studio.
    When I run it manually it works fine.
    However when it is deployed using SCCM as a package, it does nothing. I can see it being executed in execmgr.log and it returns a code of 0 but it's as though none of the code has been executed. The very fist line of the main form load event writes something to the event viewer and that doesn't appear.
    Any tricks with Windows form apps and SCCM?

    #38330
    Profile photo of Justin King
    Justin King
    Participant

    well windows forms create GUIs, and by default SCCM installs in the system context.

    I would start by changing the package delivery to install in the current user context and see how it behaves.

    Generally you don't want prompts when you push an app via SCCM, however. You want it to silently run then return a code on success/failure so SCCM can return the proper report/take appropriate action (0 for success, 1 error, etc.).

    EDIT: Here's a very simple PS wrapper I tend to use when doing an install. Just look at how it ONLY returns a 0 or a 1 back to SCCM on success/failure. Nothing directly to the user:

    #Set Install Variables
    $Application = '\setup\nwsapsetup.exe'
    $Arguments = '/silent /l'
    #If PSVersion is too early, generate $PSScriptRoot variable
    If (!$PSScriptRoot) {
    	$PSSCriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
        }
    
    #Try the Install and return results
    Try {
        $AppFullPath = $PSScriptRoot+'\'+$Application
        start-process -FilePath $AppFullPath -ArgumentList $Arguments -wait
        }
    Catch {
        Write-Error -Message $_
        Exit 1
        }
    Exit 0
    
    #38331
    Profile photo of David Zemdegs
    David Zemdegs
    Participant

    Thanks.
    This exe has to run with or without a user logged on. I'm guessing that's not possible with SCCM.
    Essentially it does a check to see if the machine needs to reboot automatically.
    If not, it just exits. If it does then I had a fancy countdown timer with other information displayed in a window – which is why I used powershell studio.
    I know I could use shutdown.exe but it has a dismissible prompt and I wanted a non dismissible window.

    #38358
    Profile photo of Justin King
    Justin King
    Participant

    It's absolutely possible to run regardless if a user is logged in or not, but not if you're using a windows form.

    Again SCCM will run in whatever context you ask of it. You have to realize that if you run in a system context then certain features wont be available, such as a HKCU branch of the registry. If your script pops up a message, that will pop up in the system context ... thus be invisible to the user. I don't have a SCCM server up and running next to me (sometimes I do) but I think there's a checkbox to allow the program to interact with the user. That _might_ get around your issue .... but again you'd have to test it.

    As for your specific issue, you can always set your collection to filter devices that have pending reboots then design two PS scripts:

    SELECT SMS_R_SYSTEM.ResourceID, SMS_R_SYSTEM.ResourceType, SMS_R_SYSTEM.Name,
    SMS_R_SYSTEM.SMSUniqueIdentifier, SMS_R_SYSTEM.ResourceDomainORWorkgroup,
    SMS_R_SYSTEM.Client FROM sms_r_system inner join SMS_UpdateComplianceStatus
    ON SMS_UpdateComplianceStatus.machineid=sms_r_system.resourceid
    WHERE SMS_UpdateComplianceStatus.LastEnforcementMessageID = 9
    

    Now that we know we have only reboot-pending devices, you can create two PS scripts and have each run in a unique context.

    First script will be in the system context, have it validate the state one more time, then if any users are currently logged in (be careful to count disconnected, otherwise oops). if the answer is no, reboot with no prompt.

    Second script will run in current user context. Same preflight check and runs your script with the GUI.

    Deploy both scripts to the above collection. Should hit all cases.

    EDIT: In hindsight I realize your basically creating a reboot prompt replacement. So I should correct the above (Ill leave original there in case others like the idea): instead of a basic collection for reboot pending, it would probably be better to create a baseline instead so that the variable is constantly checked for. Then you could inject your PS script into that so that it is run whenever the restart pending flag is triggered. the detection can run regardless of user login that way ... but have the correction be the script that only runs in the user context. Machines wont ever auto-reboot ... but the moment they log in the script should execute telling them it's time for a reboot.

    #38362
    Profile photo of David Zemdegs
    David Zemdegs
    Participant

    Thanks
    I am not looking at reboot pending. We have an AD extensionattribute that controls reboots which is what my script checks. If no-one is logged on and the script determines there is a reboot, then it needs to reboot even if the script tries to display a countdown timer. If someone is logged on, then they will see the timer which is what I wanted to achieve.

    #38364
    Profile photo of David Zemdegs
    David Zemdegs
    Participant

    These guys have a great window with tons of options. I still want the reboot to take place even if no-one is logged on.
    http://www.albany.edu/reboot2.png

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.