Logoff users with a script?

lf4

New member
Local time
3:16 PM
Messages
3
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

OS
Windows 7 Ultimate x64
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"[/QUOTE]
 

My Computer

Computer type
PC/Desktop
OS
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:
Set wshShell = WScript.CreateObject ("WSCript.shell")
wshshell.run "shutdown /l /t 0"

Thanks Samunition I'll give that a try.
LF4
 

My Computer

OS
Windows 7 Ultimate x64
I hope it does
 

My Computer

Computer type
PC/Desktop
OS
Windows 7 Ultimate X86(32 Bit)
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

OS
XP / Win7 x64 Pro
CPU
Intel Quad-Core Q9450 @ 3.2GHz
Motherboard
Asus P5-E
Memory
2x2GB GSkill DDR2
Graphics Card(s)
NVIDIA GeForce 8600 GTS (EVGA)
Monitor(s) Displays
Dell 2408WFP
Screen Resolution
1920x1200
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

OS
XP / Win7 x64 Pro
CPU
Intel Quad-Core Q9450 @ 3.2GHz
Motherboard
Asus P5-E
Memory
2x2GB GSkill DDR2
Graphics Card(s)
NVIDIA GeForce 8600 GTS (EVGA)
Monitor(s) Displays
Dell 2408WFP
Screen Resolution
1920x1200
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

Computer type
Laptop
Computer Manufacturer/Model Number
ASUS G60-RBBX05
OS
Win7 Home Premium 64x
CPU
Intel Core 2 Duo P7450 / 2.13 GHz (2.29 with Extreme Turbo)
Memory
4 GB PC-6400 Hyundai (2X2) at 800Mhz
Graphics Card(s)
NVIDIA GeForce GTX 260M 1GB DDR3 VRAM
Monitor(s) Displays
16" LED Backlit
Screen Resolution
1366 x 768 on laptop 1600x1050 max res on 22" external mon
Hard Drives
OCZ Agility 3 60GB SSD / 320 GB - Serial ATA-150 - 7200 rpm
PSU
6-cell Lithium ion { lasts 1.5 hours }
Case
ASUS G60 Laptop
Keyboard
Chicklet type back-lit (white light) keyboard
Mouse
Logitech G9 Laser Mouse 3200dpi and 1000 reports per minute
Internet Speed
Comcast 8.60mb/s up - 3.11mb/s down
Antivirus
MSE
Browser
Firefox
Other Info
General mid-budget gaming Comp. Low batterylife - High FrameRates - currently overheating problems :(

2nd Rig: Case: Rosewill BLACKHAWK Gaming ATX Mid Tower Computer Case

Mobo: GIGABYTE GA-990FXA-UD3
CPU: AMD FX-6200 Zambezi 3.8GHz (4.1GHz Turbo)
Heatsink: COOLER MASTER V8 CPU Cooler
RAM: Patriot Viper 3 8GB (2 x 4GB) 240-Pin DDR3 SDRAM 1866 (PC3 15000)
GPU: SAPPHIRE Radeon HD 6850 1GB 2
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.

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

OS
Windows 7 Ultimate x64
Back
Top