script to log off users from server

Discussion in 'Scripting' started by Sue, Mar 29, 2009.

  1. Sue

    Sue Guest

    hello. Also thankyou Pegasus for your last script.
    I need a script to log off users from my SBS 2003 server. I have told them
    they have to do it, but sometimes they forget.
    A little info about the server
    users folders are redirected to the server.
     
    Sue, Mar 29, 2009
    #1
    1. Advertisements

  2. Sue

    Sue Guest

    I found psshutdown.exe and the command, just wondering if there is another
    way.
     
    Sue, Mar 29, 2009
    #2
    1. Advertisements

  3. Have a look at the native shutdown.exe command.
     
    Pegasus [MVP], Mar 29, 2009
    #3
  4. ....but note that if users have open files, they'll lose changes.
    As a wise man said, "There are seldom good technological solutions to
    behavioral problems."
     
    Lanwench [MVP - Exchange], Mar 29, 2009
    #4
  5. "Lanwench [MVP - Exchange]"
    Well said . . . but are you sure it wasn't a wise woman who said it? :)
     
    Pegasus [MVP], Mar 29, 2009
    #5
  6. Sue

    Al Dunbar Guest

    ROFLOL!

    /Al

    PS: not funny because one might think that a "wise woman" was an oxymoron,
    but because one wise woman (or wise wench, as it were) neglected to make
    such an insightful point herself!
     
    Al Dunbar, Mar 29, 2009
    #6
  7. Nope. It was the inimitable Mr. Ed Crowley of fame, myth and lore.
     
    Lanwench [MVP - Exchange], Mar 30, 2009
    #7
  8. Ptui. I'm just an idiot who can google real fast. ;-)
     
    Lanwench [MVP - Exchange], Mar 30, 2009
    #8
  9. Sue

    Revenger Guest

    Try this batch file ... I wrote it for a coleague of mine who had to
    disconnect RDP sessions to make a backup:

    echo off
    FOR /F "usebackq delims== " %%i IN (`"query session | find "rdp-tcp#""`) DO
    logoff %%i

    You have to run this from the console session ... It will disconnect all
    users except the one where the script is running from.
     
    Revenger, Mar 31, 2009
    #9
  10. Sue

    Sue Guest

    I don't think that last script would work, becuase the users are going in
    from the lan, not remote.
     
    Sue, Apr 2, 2009
    #10
  11. Sue

    Revenger Guest

    You mean via file sharing?
    If that is the case, try using net session with the script I sent ...

    The command goes something like this: NET SESSION \\Computername /DELETE
     
    Revenger, Apr 2, 2009
    #11
  12. Sue

    Sue Guest

    Will try it thankyou.
     
    Sue, Apr 2, 2009
    #12

  13. You could give my script a try:
    Code:
    '=======================================================================
    ===
    ' ForceLogoff.vbs
    ' By Mark MacLachlan, The Spider's Parlor
    ' Usage- Double click and enter a machine name or IP address to force
    logoff
    '
    '    This code is Copyright (c) 2006 The Spider's Parlor.
    '
    '    All rights reserved.
    '
    '    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
    '    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED To
    '    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
    '    PARTICULAR PURPOSE.'
    '
    '    IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS RESPECTIVE
    SUPPLIERS BE
    '    LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
    '    DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
    '    WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
    '    ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
    '    OF THIS CODE OR INFORMATION.
    '
    ' COMMENT: Note that this script will wait for user input if a password
    protected
    '          screen saver is enabled.
    '
    '=======================================================================
    ===
    On Error Resume Next
    Const FORCE    = 4
    mname = InputBox("Enter Machine Name", "Force Logoff of Machine")
    If Len(mname) = 0 Then Wscript.Quit
    
    if Msgbox("Are you sure you want to force logoff on machine " & mname,
    vbYesNo, "Force Logoff of Machine") = vbYes then
    
    Set OpSysSet =
    GetObject("winmgmts:{impersonationLevel=impersonate,(RemoteShutdown)}//"
    & mname).ExecQuery("select * from Win32_OperatingSystem where
    Primary=true")
    for each OpSys in OpSysSet
    OpSys.Win32Shutdown FORCE
    next
    end If
    
    
    --
     
    Mark D. MacLachlan, Jul 1, 2009
    #13
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.