Logoff users with a script?


  1. lf4
    Posts : 3
    Windows 7 Ultimate x64
       #1

    Logoff users with a script?


    Hello,

    The issue I have is my co-workers and I share a VM which we remote into, only one person needs access to it at a time. I have been searching for a way that I could set a script to run when I log on which would log off all other users on the system. I have tried to do it with a simple batch file but I couldn't figure out if that was possible with other users or it would only work with the user logged in.

    I'm trying to do it by a script not using the task manager to log off users.

    Any ideas on how I might be able to accomplish this?

    Thank you,
    LF4

    Batch File to try and log off multiple users:
    Code:
    @echo off
    rem Genereate a file and store each user name we want to log off in it.
    set file=templist.txt
    echo user1 >> %file%
    echo user2 >> %file%
    echo user3 >> %file%
    
    rem Log off the users found in the file.
    FOR /f %%i in (./%file%) do (
    echo Logging off: %%i
    rem 
    Shutdown /f /l %%i
    )
    rem Remove the temp file that stored the user names.
    del %file%
    pause
      My Computer


  2. Posts : 44
    Windows 7 Ultimate X86(32 Bit)
       #2

    Here is a Vbs Script so paste it into notepad and call it *.vbs that logs others off imediatlyif you could get someone else to find out how to do it all the time just by looging it it would be great
    Code:
    Set wshShell = WScript.CreateObject ("WSCript.shell") wshshell.run "shutdown /l /t 0"
      My Computer


  3. lf4
    Posts : 3
    Windows 7 Ultimate x64
    Thread Starter
       #3

    Samunition said:
    Here is a Vbs Script so paste it into notepad and call it *.vbs that logs others off imediatlyif you could get someone else to find out how to do it all the time just by looging it it would be great
    Code:
    Set wshShell = WScript.CreateObject ("WSCript.shell")
    wshshell.run "shutdown /l /t 0"
    Thanks Samunition I'll give that a try.
    LF4
      My Computer


  4. Posts : 44
    Windows 7 Ultimate X86(32 Bit)
       #4

    I hope it does
      My Computer


  5. Posts : 1,814
    XP / Win7 x64 Pro
       #5

    Any script that you run as yourself, will only run upon logging you in. Your login process starts before any batch file runs, so in essence it would only run after you began to log on, and would then log you off.

    Also, in your batch file, I'm unsure how you would get the user names to log off that did not include your own user name each time, unless you used scripting to retrieve the currently logged in user's name (yours) and extract that from the list of all user names. At this point, that sounds quite involved.

    Could the simplest solution simply be to disallow concurrent remote logons? What VM and OS are you using?
      My Computer


  6. Posts : 1,814
    XP / Win7 x64 Pro
       #6

    lf4 said:
    Samunition said:
    Here is a Vbs Script so paste it into notepad and call it *.vbs that logs others off imediatlyif you could get someone else to find out how to do it all the time just by looging it it would be great
    Code:
    Set wshShell = WScript.CreateObject ("WSCript.shell")
    wshshell.run "shutdown /l /t 0"
    Thanks Samunition I'll give that a try.
    LF4
    That command doesn't log off all others on a system, it's simply a logoff command for the currently logged-in user.
      My Computer


  7. Posts : 3,300
    Win7 Home Premium 64x
       #7

    I am wondering what you are using as well. I use mainly Remote Desktop.

    If you are using the Remote Desktop (mstsc.ext), then you could use

    %windir%\system32\mstsc.exe /admin
    /admin kicks all other users out of the environment. Most of the VM images I access are set up in this manner. Not sure what you are using though.
      My Computer


  8. lf4
    Posts : 3
    Windows 7 Ultimate x64
    Thread Starter
       #8

    FliGi7 said:
    Any script that you run as yourself, will only run upon logging you in. Your login process starts before any batch file runs, so in essence it would only run after you began to log on, and would then log you off.

    Also, in your batch file, I'm unsure how you would get the user names to log off that did not include your own user name each time, unless you used scripting to retrieve the currently logged in user's name (yours) and extract that from the list of all user names. At this point, that sounds quite involved.

    Could the simplest solution simply be to disallow concurrent remote logons? What VM and OS are you using?
    Yes I understand that the batch script would only run after login (this is what I wanted). The users list of the system is small and yes I just figured hard coding the list in and just not adding my name to it. It's ESXi running Windows Vista x86 Business. I did notice that the VB from before would just logoff the current user.

    Thorsen said:
    I am wondering what you are using as well. I use mainly Remote Desktop.

    If you are using the Remote Desktop (mstsc.ext), then you could use

    %windir%\system32\mstsc.exe /admin
    /admin kicks all other users out of the environment. Most of the VM images I access are set up in this manner. Not sure what you are using though.
    That is correct, and it sounds like the best idea to try. Currently there are no other users logged in with their sessions disconnected. So I have no way of confirming if it will work.

    Thanks for the help and ideas,
    LF4
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 21:32.
Find Us