+ Post New Thread
Results 1 to 8 of 8
Scripts Thread, VBS loggof depending on machine name in Coding and Web Development; hi there, is it possible to logoff someone in a VBS startup script depending on the computer name? i ahve ...
  1. #1

    Join Date
    Jul 2009
    Posts
    237
    Thank Post
    6
    Thanked 38 Times in 34 Posts
    Rep Power
    12

    VBS loggof depending on machine name

    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.

  2. IDG Tech News
  3. #2
    ricki's Avatar
    Join Date
    Jul 2005
    Location
    uk
    Posts
    1,425
    Thank Post
    19
    Thanked 159 Times in 152 Posts
    Rep Power
    48
    Hi

    I dont use a vbs script I use abtutor. Its cheap and works like a dream.

    Richard

  4. #3
    browolf's Avatar
    Join Date
    Jun 2005
    Location
    Mars
    Posts
    1,425
    Blog Entries
    43
    Thank Post
    80
    Thanked 78 Times in 65 Posts
    Rep Power
    35
    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.

  5. #4
    cookie_monster's Avatar
    Join Date
    May 2007
    Location
    Derbyshire
    Posts
    4,124
    Thank Post
    364
    Thanked 271 Times in 233 Posts
    Rep Power
    71
    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.

  6. #5


    Join Date
    Mar 2009
    Location
    Leeds
    Posts
    4,761
    Thank Post
    170
    Thanked 642 Times in 555 Posts
    Rep Power
    204
    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

  7. #6

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,122
    Blog Entries
    2
    Thank Post
    111
    Thanked 516 Times in 446 Posts
    Rep Power
    117
    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

  8. #7

    Join Date
    Jan 2006
    Location
    Surburbia
    Posts
    2,178
    Thank Post
    74
    Thanked 305 Times in 243 Posts
    Rep Power
    112
    shutdown using pure vbs isnt too reliable.
    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.

    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.

  9. #8
    round2it's Avatar
    Join Date
    May 2009
    Location
    UK
    Posts
    821
    Thank Post
    149
    Thanked 99 Times in 82 Posts
    Rep Power
    27
    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.

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 6
    Last Post: 21st June 2009, 11:17 AM
  2. A little .vbs help please
    By ozzy in forum Scripts
    Replies: 9
    Last Post: 27th February 2009, 08:07 AM
  3. Permissions for VBS
    By Chrish5 in forum Windows
    Replies: 6
    Last Post: 1st October 2008, 09:23 AM
  4. Replies: 2
    Last Post: 11th May 2007, 02:33 PM
  5. Replies: 14
    Last Post: 15th October 2006, 12:19 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •