远程和以编程方式注销活动域用户

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了远程和以编程方式注销活动域用户相关的知识,希望对你有一定的参考价值。

我需要能够从程序的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

以上是关于远程和以编程方式注销活动域用户的主要内容,如果未能解决你的问题,请参考以下文章

根据活动(即可见)片段以编程方式启用或禁用按钮

如何在没有 XML 的情况下以编程方式将片段添加到活动

如何制作 parse.com 注销按钮以将我带到另一个让我登录或注册的活动?

以编程方式注销 ASP.NET 用户

如何以编程方式“重新启动”android应用程序[重复]

您如何在 spring-security 中注销所有已登录的用户?