Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Logoff users with a script?


30 Nov 2010   #1
lf4

Windows 7 Ultimate x64
 
 
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 System SpecsSystem Spec
.

30 Nov 2010   #2

Windows 7 Ultimate X86(32 Bit)
 
 

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:
Quote:
Set wshShell = WScript.CreateObject ("WSCript.shell") wshshell.run "shutdown /l /t 0"
My System SpecsSystem Spec
30 Nov 2010   #3
lf4

Windows 7 Ultimate x64
 
 

Quote   Quote: Originally Posted by Samunition View Post
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 System SpecsSystem Spec
.


30 Nov 2010   #4

Windows 7 Ultimate X86(32 Bit)
 
 

I hope it does
My System SpecsSystem Spec
30 Nov 2010   #5

XP / Win7 x64 Pro
 
 

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 System SpecsSystem Spec
30 Nov 2010   #6

XP / Win7 x64 Pro
 
 

Quote   Quote: Originally Posted by lf4 View Post
Quote   Quote: Originally Posted by Samunition View Post
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 System SpecsSystem Spec
30 Nov 2010   #7

Win7 Home Premium 64x
 
 

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

Quote:
%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 System SpecsSystem Spec
14 Dec 2010   #8
lf4

Windows 7 Ultimate x64
 
 

Quote   Quote: Originally Posted by FliGi7 View Post
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.

Quote   Quote: Originally Posted by Thorsen View Post
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

Quote:
%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 System SpecsSystem Spec
Reply

 Logoff users with a script?




Thread Tools



Similar help and support threads for2: Logoff users with a script?
Thread Forum
Solved Remote Logoff Users? Network & Sharing
Logon Script Runs for Some Users But Not Others Network & Sharing
Solved Logoff script not running at shutdown General Discussion
Is there a way to execute a prgm/script at user logoff/shutdown? General Discussion
Logoff script timeout? General Discussion
Use GP or logon/logoff script Network & Sharing
Locked users logoff with administrator General Discussion

Our Sites

Site Links

About Us

Find 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 12:49 AM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33