hi there, is it possible to logoff someone in a VBS startup script depending on the computer name?
i ahve been googling this for hours and canot find anything
if computer name starts with DT-T then logoff
Hope you get what i mean.
hi there, is it possible to logoff someone in a VBS startup script depending on the computer name?
i ahve been googling this for hours and canot find anything
if computer name starts with DT-T then logoff
Hope you get what i mean.
Hi
I dont use a vbs script I use abtutor. Its cheap and works like a dream.
Richard
shutdown using pure vbs isnt too reliable.
I use down.exe from lstools instead (although not for start up scripts)
LoSOFT
in dos you can do
if %computername:~0,4% == DT-T (
down %computername% /P /Q
)
in wsh you can access the computer name with
Set WshNetwork = WScript.CreateObject("WScript.Network")
WScript.Echo "Computer Name = " & WshNetwork.ComputerName
do a comparison and then exec the dos command for down.
Last edited by browolf; 9th March 2010 at 02:23 PM.
You can use PsShutdown and call it from a .bat file.
PsShutdown
C:\psshutdown.exe -o @C:\PCNameList.txt (o - Logoff the console user. )
Last edited by cookie_monster; 9th March 2010 at 02:26 PM.

you could just create a group for users then on the ou (or group of pcs in ad) deny their user group interactive logon privileges then they cant even log on to them
You can't do it with a startup script (because the user can't log on until that's finished) but you could do it with a logon script.
Googling for a complete idea like this can be tricky - split it up into the bits you want "find computer name in vbscript" "log off user vbscript" and you'll probably find the stuff you need.
In the code below, I get the username and computername - they're converted to upper case because it then makes checking easier.
all this will do is stop user "STEVE" from logging on to computer "COMPUTER02" - you probably want something more sophisticated. For example, @browolf has posted a batch file to deal with computers where the first 4 letters are "DT-T" - you can do something like:
if left(sComputer,4)="DT-T" then
or you might have:
if left(sComputer,5)="MA215" or left(sComputer,2)="IT" then
to pick particular groups of users.
Hint - while you're debugging, don't log the user off - it will drive you mad :-) Instead, comment out the "logoff" line and put msgbox "logging off" You'll then just get a message if you would be logged off.
Code:set oNet=createobject("wscript.network") sComputer=ucase(oNet.computername) sUser=ucase(oNet.username) if sUser="STEVE" then if sComputer="COMPUTER02" then logoff end if end if sub Logoff Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}!\\.\root\cimv2") For Each obj in oWMI.ExecQuery("Select * from Win32_OperatingSystem") Set oOS = obj Exit For Next Const EWX_FORCE = 4 Const EWX_LOGOFF = 0 oOS.Win32shutdown EWX_FORCE +EWX_LOGOFF end sub
Mmm.. I do JS scripts (ultimately no difference), tried this with essentially the same WMI above and reached the same conclusion for a restart i.e. using an identical reverted to snapshot test VM sometimes it just didn't happen for no obvious reason.shutdown using pure vbs isnt too reliable.
Psshutdown annoyed me for 10 minutes coz once again again I forgot the accepteula switch, so I stroppily ended up making a very little unmanaged C++ app to make the system call (same parameters, so must be the one WMI hits) - and it has worked every time.
It's a mystery, best I could think of is that maybe WMI hadn't quite got going when I called it in the script which was firing during startup. It wasn't a factor in my tests, but WMI is also one of those areas that can get trashed in a large variety of interesting ways.
are you wanting the script to deny access to a machine for certain users?
if so then the gpo way mentioned above is the way i would go.
2pence worth
Last edited by round2it; 9th March 2010 at 09:31 PM.
There are currently 1 users browsing this thread. (0 members and 1 guests)