shutdown

最後更新: 2021-03-19

介紹

 


Windows

 

Location:

C:\Windows\System32\shutdown.exe

Opts

  • /r          # 將電腦關機並重啟
  • /s          # 將電腦關機
    ---
  • /f           # Force running applications to close without forewarning users.
    ---
  • /a          # 中止系統關機/重啟
    ---
  • /t n        # 在 n 秒後關機. 預設 30 秒後
    ---
  • /c "s"     # Comment

Exampe: schedule 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 /t 3

 


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. reboot

# b => 叫 kernel 立即 reboot !!

# o => 關機

echo b > /proc/sysrq-trigger