free log
CRM

Bozteck VNCScan Community

Community makes things happen
Welcome to Bozteck VNCScan Community Sign in | Join | Help
in
Home Forums

Logoff user/unlock workstation on remote computer

Last post 08-03-2007, 8:01 AM by AlanK. 1 replies.
Sort Posts: Previous Next
  •  08-01-2007, 10:09 AM 2048

    Logoff user/unlock workstation on remote computer

    Here's a simple local command to logoff a locked user session without connecting and logging in as administrator. You'll need PSSHUTDOWN from the Microsoft PStools.
    http://www.microsoft.com/technet/sysinternals/Utilities/PsTools.mspx

    psshutdown -o -f  \\%HOST%
  •  08-03-2007, 8:01 AM 2050 in reply to 2048

    Re: Logoff user/unlock workstation on remote computer

    Well, PSTools is the easy way to do it, but for those of us who prefer to roll their own, here's a vbscript that will do the same thing.  I like something that I can customize.

    Be aware that regardless of which way you do it, either psshutdown or a script, both of them use the "force" option which closes all open programs without saving files, so don't use them unless you are sure that nothing will be lost.

    This is where a script can come in handy.  The script below is pretty basic, but can be modified to search through running processes on the remote computer for critical ones and can take steps to abort or save files as appropriate.

    '========================================================
    Dim strComputer, strAction, nAction, oLocator, oConnection, oWindows, oSys
    If WScript.Arguments.count = 2 Then
        strComputer = UCase(WScript.Arguments(0))
        strAction = UCase(WScript.Arguments(1))
    Else
        WScript.Echo "restart.vbs strComputer strAction (REBOOT, LOGOUT, SHUTDOWN)"
        WScript.Quit
    End If

    Const EWX_LOGOFF = 0
    Const EWX_SHUTDOWN = 1
    Const EWX_REBOOT = 2
    Const EWX_FORCE = 4
    Const EWX_POWEROFF = 8
       
    Select Case strAction
    Case "REBOOT": nAction = EWX_REBOOT + EWX_FORCE
    Case "LOGOUT": nAction = EWX_LOGOFF + EWX_FORCE
    Case "SHUTDOWN": nAction = EWX_POWEROFF + EWX_FORCE
    Case Else
        WScript.Quit
    End Select

    Set oLocator = CreateObject("WbemScripting.SWbemLocator")
    Set oConnection = oLocator.ConnectServer(strComputer,"root\cimv2")
    Set oWindows = oConnection.ExecQuery("Select Name From Win32_OperatingSystem")
    For Each oSys In oWindows
        oSys.Win32ShutDown(nAction)
    Next
    '========================================================

    Just save it as restart.vbs and run it as a custom command like this:

    restart.vbs %HOST% LOGOUT

    You can also make it a remote script by removing all the lines before the first CONST line and replacing them with:

    strComputer = "."
    strAction = "LOGOUT"

    --Alan--

View as RSS news feed in XML
Powered by Community Server, by Telligent Systems