none
Powershell script needs to display message box to user... RRS feed

  • Question

  • Hi everyone-

    Hope this is an easy one as i am new to running PShell scripts via SCCM/pkgs.

    I have a script(below) that generates a msgBox to the user asking them to log out and needs to be displayed once the pkg is downloaded to the client.

    Manually(running the script locally), this script does exactly what i need. Trouble is, i need it to be delivered via pkg/adv and run in the same manner.

    What i see once the pkg runs on the client is a quick DOS screen flash listing the path where Pshell lives...this is where i need it to actually display the msgBox to the user giving them the option to logoff...works fine locally, just not through pkg delivery.

    My command line in the package is: powershell.exe -ExecutionPolicy Bypass -scope CurrentUser -File logoffMSG2.ps1

    I've tested various configs within the program properties, but still no luck...
    Example...
    (Only when user is logged in-Allow users to interact with program[checked])
    (Run with admin rights/Run with users rights)
    The advertsment status shows success on all tests, but i know thats a somewhat a limited perspective.
    This feels like a LOCAL/USER context issue, but again....kinda new to the scripting world. Any help would be great...
    Thanks

    PShell script -

    Add-type –AssemblyName System.Windows.Forms
    $OUTPUT= [System.Windows.Forms.MessageBox]::Show("Please Logoff to allow important updates to begin. Select YES to logoff now, or NO to logoff at another time. Thank you, JL IT." , "***JL IT - Log Off for Updates***" , 4)

    if ($OUTPUT -eq "YES" )
    {

    cmd /c logoff

    }
    else
    {

    [System.Windows.Forms.MessageBox]::Show("Please Log Off when possible to recieve updates- thanks" , "***JL IT - Log Off for Updates***" , 0)

    }

     

    Tuesday, September 17, 2013 1:31 AM

Answers

  • Hi strato-ashevilleNC,

    I have this working as part of a task sequence in SCCM 2007 (I'm sure with a little tweaking it could be used as part of a package deployment). To get it working, I created a package with the following files:

    cmd.exe (from a windows 7 x64 installation)

    CopylogoffMSG2.bat (script content below):
    cmd.exe /c xcopy.exe "%~dp0*.*" "C:\Program Files (x86)\XX\logoffMSG2" /E /Z /Y /I
    del "C:\Program Files (x86)\XX\logoffMSG2\CopylogoffMSG2.bat"

    cscript.exe (from a windows 7 x64 installation)

    hideTsProgressUi.vbs (script content below):
    Set oTSProgressUI = CreateObject("Microsoft.SMS.TSProgressUI")
    oTSProgressUI.CloseProgressDialog
    Set oTSProgressUI = Nothing

    logoffMSG2.ps1 (your file)

    powershell.exe (from a windows 7 x64 installation)

    ServiceUI.exe (search for it on google)

    I then created a task sequence with the following steps:

    Copy logoffMSG2 Locally: run command line, use package created above and execute the CopylogoffMSG2.bat file from that package

    Prompt for Logoff: run command line with the following set to run (don't forget to change the start in to "C:\Program Files (x86)\XX\logoffMSG2"):

    cmd.exe /C cscript.exe hideTsProgressUi.vbs & ServiceUI.exe -process:tsprogressui.exe powershell.exe -ExecutionPolicy Bypass -windowstyle hidden -File logoffMSG2.ps1

    Please let me know if this works for you.

    Thanks,

    Paul

    • Marked as answer by Juke Chou Sunday, September 22, 2013 10:26 AM
    Thursday, September 19, 2013 4:33 PM

All replies

  • Forgot to mention i also edited the cmd line scope parameter to -scope CurrentUser and LocalMachine.
    thanks

    Tuesday, September 17, 2013 2:32 AM
  • Hi strato-ashevilleNC, 

    I think the issue is one I've encountered before. Because the SCCM Task Manager process runs as system, the dialog is being presented to the wrong session. You can use serviceui to present the dialog to the user. I'll post more detail tomorrow.

    Thanks, 

    Paul


    Wednesday, September 18, 2013 11:56 PM
  • Hi strato-ashevilleNC,

    I have this working as part of a task sequence in SCCM 2007 (I'm sure with a little tweaking it could be used as part of a package deployment). To get it working, I created a package with the following files:

    cmd.exe (from a windows 7 x64 installation)

    CopylogoffMSG2.bat (script content below):
    cmd.exe /c xcopy.exe "%~dp0*.*" "C:\Program Files (x86)\XX\logoffMSG2" /E /Z /Y /I
    del "C:\Program Files (x86)\XX\logoffMSG2\CopylogoffMSG2.bat"

    cscript.exe (from a windows 7 x64 installation)

    hideTsProgressUi.vbs (script content below):
    Set oTSProgressUI = CreateObject("Microsoft.SMS.TSProgressUI")
    oTSProgressUI.CloseProgressDialog
    Set oTSProgressUI = Nothing

    logoffMSG2.ps1 (your file)

    powershell.exe (from a windows 7 x64 installation)

    ServiceUI.exe (search for it on google)

    I then created a task sequence with the following steps:

    Copy logoffMSG2 Locally: run command line, use package created above and execute the CopylogoffMSG2.bat file from that package

    Prompt for Logoff: run command line with the following set to run (don't forget to change the start in to "C:\Program Files (x86)\XX\logoffMSG2"):

    cmd.exe /C cscript.exe hideTsProgressUi.vbs & ServiceUI.exe -process:tsprogressui.exe powershell.exe -ExecutionPolicy Bypass -windowstyle hidden -File logoffMSG2.ps1

    Please let me know if this works for you.

    Thanks,

    Paul

    • Marked as answer by Juke Chou Sunday, September 22, 2013 10:26 AM
    Thursday, September 19, 2013 4:33 PM
  • Thank Paul...and sorry for the delay in responding...work has been a bear.

    Very helpful solution that you have there..i wasnt sure if it was x64 specific...so i toyed around with the passes in a SCCM pacakge and found what i was doing wrong...

    I needed to seperate the "Set-execution policy" and give it its own Program THEN send a powershell.exe -File pass in next Program.
    I'm not sure if this is the most efficient way to accomplish this but in this case i didn't have to create anything that i didn't already have.

    Also, i found that the -WindowStyle Hidden switch useful in keeping the MsgBox "tidy" when being displayed to the user(prevents the actual Shell from being visible, only the MsgBox shows).

    Add-type –AssemblyName System.Windows.Forms
    $OUTPUT= [System.Windows.Forms.MessageBox]::Show("Please Logoff to allow important updates to begin.                                             Select YES to logoff now, or NO to logoff at another time. Thank you, JL IT." , "***JL IT - Log Off for Updates***" , 4)

    if ($OUTPUT -eq "YES" )
    {

    cmd /c logoff


    }
    else
    {

    [System.Windows.Forms.MessageBox]::Show("Please Log Off when possible to recieve updates- thanks" , "***JL IT - Log Off for Updates***" , 0)

    }

    thanks again for your help Paul...definitely will give this other option a shot
    randy

    Monday, September 23, 2013 9:28 PM
  • Hi strato-ashevilleNC,

    Glad you found it useful. Just a note, I do believe the set-executionpolicy piece is handled when calling the file itself:

    cmd.exe /C cscript.exe hideTsProgressUi.vbs & ServiceUI.exe -process:tsprogressui.exe powershell.exe -ExecutionPolicy Bypass -windowstyle hidden -File logoffMSG2.ps1

    Did that not work for you? As for x64, this should work in both 32 & 64 bit, just modify the path an grab the appropriate version(s) of cmd/cscript/powershell.

    Thanks,

    Paul

    Wednesday, September 25, 2013 3:04 PM