简体   繁体   中英

Random Shutdown Timer with powershell and no popup and hidden

Hi i try a cmd file or powershell file to shutdown a pc after a random time 20h and 24h with no popup message that the pc is shutting down in 10 minutes... and hidden

i try this

shutdown -r -t 86400 -c " "

Sekond way:

start powershell.exe -WindowStyle Hidden -Command "sleep 86400; shutdown -r -t 00"

but without random time between 20h and 24h

The PowerShell command to generate a random number in a range followed by the execution of shutdown.exe looks like that

$timeInSeconds = Get-Random -Minimum (20*3600) -Maximum (24*3600+1)
Start-Sleep -Seconds $timeInSeconds
shutdown.exe /r /t 0

if you really need a ugly oneliner than this might do what you need:\

powershell -WindowStyle Hidden -Command "$timeInSeconds = Get-Random -Minimum (20*3600) -Maximum (24*3600+1); Start-Sleep -Seconds $timeInSeconds; shutdown.exe /r /t 0"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM