最後更新: 2021-03-19
介紹
Windows
Location:
C:\Windows\System32\shutdown.exe
Opts
- /r # 將電腦關機並重啟
- /s # 將電腦關機
- /l # logout
- /t n # 在 n 秒後執行 "/r" 或 "/s". 預設 30 秒後. 最小 1
--------
- /f # Force running applications to close without forewarning users.
- /a # 中止系統關機/重啟
--------
- /c "string" # Comment
Exampe: schedule a reboot:
名稱 reboot system (one time)
程式: C:\Windows\System32\shutdown.exe
引數: /r /t 60
設定時間: "觸發程序"
* 不論使用者登入與否均執行
* 以最高權限執行 (bypass UAC(User Account Control)保護)
Exampe: UPS.cmd
C:\Windows\System32\shutdown.exe /s /c "UPS shutdown it" /t 3
AutoEndTasks
Registry: HKCU\Control Panel\Desktop
AutoEndTasks # String
Windows normally displays an “force shut down” button after the number of seconds expires,
asking for your permission to close any running applications.
0 = Off
1 = On
WaitToKillAppTimeout # String, Unit ms, Default: 20000
When you shutdown your PC, Windows gives open applications 20 seconds
to clean up and save their data before offering to close them.
If this threshold is exceeded, the End Task dialog box appears
HungAppTimeout # String, Unit ms, Default: 5000
Windows considers applications “hung” if they don’t respond within 5 seconds and
gives you a “force shut down” option.
Daily Reboot
Using "task scheduler" to daily reboot
Win+R > taskschd.msc > Right-click "New Folder: MyTasks"
> Right-click "Create Task..." >
Tab1: General
- Name: Daily Reboot
- Run whether user is logged on or now
Tab2: Triggers
New...
- Settings: Daily
Tab3: Actions
New...
- Program/script: shutdown
- Add arguments: /r /c "Daily scheduled reboot"
- Start in: C:\Windows\System32
Check: Event log
Win+R > eventvwr >
系統(Source: USER32, ID: 1074, 註解: Daily scheduled reboot)
30 秒後
Source: Kernel-Power, ID: 109
Remote shutdown Windows
On Remote Windows
1. Start “Remote Registry” service (RemoteRegistry)
2. Firewall allow "Windows Management Instrumentation" (WMI) # 445/TCP
Test on Windows
Shutdown by GUI
# "/i" Display "Remote Shutdown Dialog"
shutdown /i
Shutdown by CLI
- /r = reboot
- /s = shutdown
shutdown /r /m \\192.168.88.122 /t 0 /c "test remote reboot"
192.168.88.122: Access is denied.(5)
net use \\192.168.88.122\IPC$ mypass /USER:user
The command completed successfully.
Shutdown by Tools - Sysinternals
PsShutdown v2.52
Support
- Client: Windows Vista and higher.
- Server: Windows Server 2008 and higher.
Opts
- -u Specifies optional user name for login to remote computer.
- -p Specifies optional password for user name.
- -k Poweroff the computer.
- -r Reboot after shutdown.
- -t Specifies the countdown in seconds until the shutdown (default: 20 seconds)
i.e.
# msg: "192.168.88.122 is scheduled to reboot in 00:00:20."
psshutdown.exe -u MyUser -p MyPass -r \\192.168.88.122
# 立即 reboot
psshutdown.exe -u MyUser -p MyPass -t 0 -r \\192.168.88.122
On Remote Windows
Event ID 1074
程序 wininit.exe (s.s.s.s) 已代表使用者 TIM-PC2\admin,啟動電腦 TIM-PC2 的 重新啟
Shutown from Linux
# "net" tool from the Samba package
apt-get install samba-common # V 4.9.5
net rpc shutdown -t 0 -U user%pass -I 192.168.88.122
Shutdown of remote machine succeeded
Linux
Usage:
shutdown [OPTION]... TIME [MESSAGE]
shutdown time [warning message]
shutdown -c <--- Cancels a running shutdown.
Example:
shutdown 22:00 & <-- 22:00 時 shutdown
shutdown +3 & <-- 3 min 後 shutdown
shutdown now <-- 現在就 shutdown
If no time argument is specified, "+1" is implied.
其他選項:
- -r # reboot
- -h # either halted or powered off // halt 與 poweroff 是有所不同!!
- -H # halted
- -P # powered off
- -k # Only send out the warning messages
- -t time # 預設值為 30
force reboot
reboot -f -n
-n Don't sync before reboot or halt. Note that the kernel and storage drivers may still sync.
halt, poweroff, shutdown
halt
terminates all processes and shuts down the cpu.
-n # Don't sync before reboot or halt.
P.S.
有時 halt 唔到的其中一個原因係 sync 唔到 (USB Backup Disk 不見了)
poweroff
exactly like halt, but it also turns off the unit itself (lights and everything on a PC).
It sends an ACPI command to the board, then to the PSU, to cut the power.
shutdown
like poweroff, but it also runs the shutdown scripts.
Force Reboot (sysrq-trigger)
當 reboot -f 唔 work 時可以用呢招
1. Enable sysrq-trigger
echo 1 > /proc/sys/kernel/sysrq
2. Force Reboot
# b => 叫 kernel 立即 reboot !!
# o => 關機
echo b > /proc/sysrq-trigger