Howdy Spiceheads!!<\/p>\n
Utilizing PowerShell, I created a ps1 that PDQ can deploy out. However, when the script executes, the Message Box is Active (pressing spacebar = yes) and if our users don’t notice it, and they hit the spacebar, their PC will restart. Anyone know of some scripting that will allow a user that doesn’t notice the message box to continue to type without it making a selection? The PS Script is below. Please don’t make fun of it, this is my first working script. Yes it is Ugly, Yeah probably a lot of stuff that wasn’t needed, but it WORKS. With the one exception. Thanks in advance. Happy Friday.<\/p>\n
$shell = New-Object -ComObject \"Shell.Application\"\n$shell.minimizeall()\n\nAdd-Type -AssemblyName PresentationCore,PresentationFramework\n\n$msgBody = \"Your device requires a system reboot to update or upgrade system software! If you feel you have received this message in error, please contact the IT Department at Extension 820.\"\n$msgTitle = \"A SYSTEM REBOOT IS REQUIRED\"\n$msgButton = 'YesNo'\n$msgImage = 'Question'\n$Result = [System.Windows.MessageBox]::Show($msgBody,$msgTitle,$msgButton,$msgImage)\nWrite-Host \"The user chose: $Result [\" ($result).value__ \"]\"\n$condition = $Result\n#if ($condition -eq 7)\n# {\n# Return\n# }\nif ($condition -eq 6)\n {\n Restart-Computer\n }\n\nexit\n<\/code><\/pre>","upvoteCount":8,"answerCount":17,"datePublished":"2022-05-13T18:29:53.000Z","author":{"@type":"Person","name":"spiceuser-54vvg","url":"https://community.spiceworks.com/u/spiceuser-54vvg"},"suggestedAnswer":[{"@type":"Answer","text":"
Advertisement
Howdy Spiceheads!!<\/p>\n
Utilizing PowerShell, I created a ps1 that PDQ can deploy out. However, when the script executes, the Message Box is Active (pressing spacebar = yes) and if our users don’t notice it, and they hit the spacebar, their PC will restart. Anyone know of some scripting that will allow a user that doesn’t notice the message box to continue to type without it making a selection? The PS Script is below. Please don’t make fun of it, this is my first working script. Yes it is Ugly, Yeah probably a lot of stuff that wasn’t needed, but it WORKS. With the one exception. Thanks in advance. Happy Friday.<\/p>\n
$shell = New-Object -ComObject \"Shell.Application\"\n$shell.minimizeall()\n\nAdd-Type -AssemblyName PresentationCore,PresentationFramework\n\n$msgBody = \"Your device requires a system reboot to update or upgrade system software! If you feel you have received this message in error, please contact the IT Department at Extension 820.\"\n$msgTitle = \"A SYSTEM REBOOT IS REQUIRED\"\n$msgButton = 'YesNo'\n$msgImage = 'Question'\n$Result = [System.Windows.MessageBox]::Show($msgBody,$msgTitle,$msgButton,$msgImage)\nWrite-Host \"The user chose: $Result [\" ($result).value__ \"]\"\n$condition = $Result\n#if ($condition -eq 7)\n# {\n# Return\n# }\nif ($condition -eq 6)\n {\n Restart-Computer\n }\n\nexit\n<\/code><\/pre>","upvoteCount":8,"datePublished":"2022-05-13T18:29:53.000Z","url":"https://community.spiceworks.com/t/create-an-inactive-message-box-in-powershell/832783/1","author":{"@type":"Person","name":"spiceuser-54vvg","url":"https://community.spiceworks.com/u/spiceuser-54vvg"}},{"@type":"Answer","text":"I’m not a programmer, but it seems the problem boils down to<\/p>\n
\n- the message box window has focus<\/li>\n
- the “Yes” button has focus (or is the default button)<\/li>\n<\/ul>\n
So, can any of these be done?<\/p>\n
\n- Set the focus to the “No” button, so that it becomes the default<\/li>\n
- If it doesn’t have a “No” button, can you change the message box type to one that has a “Yes” and “No”<\/li>\n
- Move the focus elsewhere by opening a secondary message box that does nothing other than warn of the other message box and pending restart<\/li>\n<\/ul>\n
I’m sure there are better ways and hopefully one of the experts will post something, but in the meantime, those are some possibilities to consider.<\/p>","upvoteCount":1,"datePublished":"2022-05-13T18:42:20.000Z","url":"https://community.spiceworks.com/t/create-an-inactive-message-box-in-powershell/832783/2","author":{"@type":"Person","name":"ich-ni-san","url":"https://community.spiceworks.com/u/ich-ni-san"}},{"@type":"Answer","text":"
One of the parameters in the MessageBox is DefaultButton. You could set that to be a cancel so inadvertent clicks or keypresses have a soft landing.<\/p>\n
Alternatively, you could set this to run after-hours with a forced restart and just warn everyone ahead of time that their desktops will restart later that evening (saving all open documents, of course)<\/p>\n