Forum Discussion
dmarquesgn
Oct 02, 2022Iron Contributor
Messagebox and action if not pressed
Hi, I'm trying to develop a script to pop-up a messagebox to a user who has the computer connected at a certain hour of the day. If the user confirms he's using the computer by pressing a button ...
dmarquesgn
Iron Contributor
In the case of a GPO I think the drawback is that will shutdown the computers even if they are at home, and the goal is just to turn off the computers which are in the office.
Meanwhile I got some code to test, to check if it works for the goal. The code is this one:
# How long to display the dialog before it closes automatically.
$timeoutSecs = 3 * 60 # 30 minutes.
# Translate this into the time of day, to show to the user.
$timeoutTimeOfDay = (Get-Date).AddSeconds($timeoutSecs).ToString('T')
# Put up a message box with a timeout and OK / Cancel buttons.
$response =
(New-Object -ComObject WScript.Shell).Popup(
@"
Your computer will shut down at $timeoutTimeOfDay.
Press OK to shut down now, or Cancel to cancel the shutdown.
"@,
$timeoutSecs,
'Pending shutdown',
49 # 48 + 1 == exclamation-point icon + OK / Cancel buttons
)
if ($response -eq 2) { # Cancel pressed.
Write-Warning 'Shutdown aborted by user request.'
exit 2
}
# OK pressed ($response -eq 1) or timed out ($response -eq -1),
# proceed with shutdown.
'Shutting down...'
# Stop-Computer -Force
Schnittlauch
Oct 10, 2022Steel Contributor
Hi dmarquesgn ,
sorry for the late response!
You can specify the scope within a GPO only to computers in your company.
In my opinion is a powershell script a overkill, the time for managing it, rolling it out etc. could get difficult.
I'll check your code the days and write u back.
Sorry,
Schnittlauch