Hi everyone,
I have a powershell script that I am executing via a scheduled task to prompt users to reboot their machines every night. The script, prompt, and reboot process work just fine now but I am having one last issue with this script.
When the scheduled task executes the dialog box does not pop up above all other windows. Instead it just has a flashing powershell icon on the taskbar which then brings up the dialog box if you click on it.
Is there a way to ensure that this popup box is displayed on top of all windows (brought to the foreground)? For reference, the current code is below:
# DEFINE SECONDS TO WAIT FOR RESPONSE $seconds_to_wait=900 # DEFINE REBOOT POSTPONE TIME IF USER CLICKS NO $rebootWaitTime = 7200 # OPEN POPUP WINDOW WITH YES/NO PROMPT $pop = New-Object -ComObject WScript.Shell $answer = $pop.Popup("Do you want to reboot now? If you click 'No' your computer will reboot automatically in 2 hours. If you do not respond to this message within 15 minutes, your computer will reboot automatically. Please remember to save your work.",$seconds_to_wait,"Nightly Reboot",4) # IF NO ANSWER AFTER $seconds_to_wait REBOOT if ($answer -eq "-1") { shutdown /r /f } # IF USER CLICKS NO, WAIT $rebootWaitTime THEN REBOOT elseif ($answer -eq "7") { Start-Sleep -Seconds $rebootWaitTime shutdown /r /f } # IF USER CLICKS YES, REBOOT IMMEDIATELY elseif ($answer -eq "6") { shutdown /r /f }
- Edited by Cosmos_85 Thursday, June 25, 2015 6:52 PM