我需要能夠從程序中從他的Windows會話中註銷任何用戶。遠程和以編程方式註銷活動域用戶
我知道我可以作爲管理員登錄並強制遠程註銷。有沒有其他方法可以在不登錄的情況下強制註銷?
該工具將作爲管理員運行,因此這不是問題,可以在不登錄的情況下進行遠程註銷。
工具是.NET,但任何其他方式都歡迎(JScript中,命令行工具從PInvoke的運行等)
我需要能夠從程序中從他的Windows會話中註銷任何用戶。遠程和以編程方式註銷活動域用戶
我知道我可以作爲管理員登錄並強制遠程註銷。有沒有其他方法可以在不登錄的情況下強制註銷?
該工具將作爲管理員運行,因此這不是問題,可以在不登錄的情況下進行遠程註銷。
工具是.NET,但任何其他方式都歡迎(JScript中,命令行工具從PInvoke的運行等)
也許與Sysinternals的PsTools,特別PsShutdown?
終於找到了這個腳本在此頁:http://www.robvanderwoude.com/files/logoff_vbs.txt
我決定把它存爲工具內部的串並使其它寫入磁盤,執行它並刪除它。不是特別優雅(是的,是的,就像地獄般醜陋),但現在足夠好了。
' Logoff.vbs, Version 1.00
' Logoff current user on any WMI enabled computer on the network
'
' Adapted from posts by Alex Angelopoulos on www.developersdex.com
' and Michael Harris on microsoft.public.scripting.vbscript
'
' Written by Rob van der Woude
' http://www.robvanderwoude.com
' Check command line parameters
Select Case WScript.Arguments.Count
Case 0
' Default is local computer if none specified
strComputer = "."
Case 1
Select Case WScript.Arguments(0)
' "?", "-?" or "/?" invoke online help
Case "?"
Syntax
Case "-?"
Syntax
Case "/?"
Syntax
Case Else
strComputer = WScript.Arguments(0)
End Select
Case Else
' More than 1 argument is not allowed
Syntax
End Select
' Define some constants that can be used in this script;
' logoff = 0 (no forced close of applications) or 5 (forced);
' 5 works OK in Windows 2000, but may result in power off in XP
Const EWX_LOGOFF = 0
Const EWX_SHUTDOWN = 1
Const EWX_REBOOT = 2
Const EWX_FORCE = 4
Const EWX_POWEROFF = 8
' Connect to computer
Set OpSysSet = GetObject("winmgmts:{(Shutdown)}//" & strComputer & "/root/cimv2").ExecQuery("select * from Win32_OperatingSystem where Primary=true")
' Actual logoff
for each OpSys in OpSysSet
OpSys.Win32Shutdown EWX_LOGOFF
next
' Done
WScript.Quit(0)
Sub Syntax
msg = vbCrLf & "Logoff.vbs, Version 1.00" & vbCrLf & _
"Logoff the current user of any WMI enabled computer on the network." & _
vbCrLf & vbCrLf & "Usage: CSCRIPT LOGOFF.VBS [ computer_name ]" & _
vbCrLf & vbCrLf & _
"Where: " & Chr(34) & "computer_name" & Chr(34) & _
" is the name of the computer to be logged off" & vbCrLf & _
" (without leading backslashes); default is " & _
Chr(34) & "." & Chr(34) & vbCrLf & _
" (the local computer)." & vbCrLf & vbCrLf & _
"Written by Rob van der Woude" & vbCrLf & _
"http://www.robvanderwoude.com" & vbCrLf & vbCrLf & _
"Based on posts by Alex Angelopoulos on www.developersdex.com" & _
vbCrLf & _
"and Michael Harris on microsoft.public.scripting.vbscript" & vbCrLf
Wscript.Echo(msg)
Wscript.Quit(1)
End Sub
你可以使用簡單的命令行從任何遠程用戶強行註銷如下
C:\>psexec \\remotepc shutdown /f /l
是的,這似乎工作過。 – 2008-10-21 14:58:36