iT邦幫忙

DAY 20
1

強而有力的 Windows PowerShell系列 第 20

使用 Windows PowerShell 登出本機電腦

這次分享數種使用 Windows PowerShell 登出本機電腦的指令操作。

強而有力的 Windows PowerShell 系列文章列表如下:
http://ithelp.ithome.com.tw/event/ironmanarticle2/id/20005121
要使用 Windows PowerShell 登出本機電腦,除了可以使用原本即可執行在**「命令提示字元」**中的工具程式之外,更可使用 Windows PowerShell 所提供的 WMI 類別。

首選是使用系統內建的 Shutdown.exe 工具,搭配登出選項的參數 -l:

Shutdown -l

第 2 種則使用微軟網站提供的 PsTools 中的 PsShutdown.exe,搭配登出選項的參數 -o。假設 PsShutdown.exe 位於 C:\PsTools 目錄中,就可以使用下面的指令來登出電腦:

C:\PsTools\PsShutdown -o

請注意

  1. 第一次使用 PsShutdown.exe 會需要同意它的使用規範,所以如果第一次就直接在 Windows PowerShell 裡執行 PsShutdown.exe,會一直停在使用規範的視窗中。此外,第一次需要使用系統管理者的身分來執行,因為它會安裝一個服務。

  2. PsShutdown.exe 已經許久沒有新版本出現,在 64-bit 的 Windows 作業系統中,可能會不能正常執行。

第 3 種方法是透過系統內建的 LogOff.exe 終止工作階段:

LogOff

最後一種方式是使用 WMI 所提供的 Win32_OperatingSystem 類別,呼叫 Win32Shutdown 方法,搭配使用 0 的旗標,即可進行登出電腦的操作:

$strComputer = "."
(Get-WmiObject -Class Win32_OperatingSystem -ComputerName $strComputer).Win32Shutdown(0)

上一篇
使用 Windows PowerShell 鎖定本機電腦
下一篇
使用 Windows PowerShell 關閉電腦以及重新啟動電腦
系列文
強而有力的 Windows PowerShell33
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言