+ Post New Thread
Results 1 to 12 of 12
Windows Thread, Login Script to Log user off if folder doesn't exsist. in Technical; Hi Please can someone tell me what I would need to put in the login script to log off a ...
  1. #1

    Join Date
    Dec 2007
    Posts
    83
    Thank Post
    2
    Thanked 1 Time in 1 Post
    Rep Power
    0

    Login Script to Log user off if folder doesn't exsist.

    Hi
    Please can someone tell me what I would need to put in the login script to log off a user if a folder doesn't exist on the local machine. Operating system is Windows 7.

    Many thanks in advance

  2. #2

    Join Date
    Dec 2007
    Posts
    83
    Thank Post
    2
    Thanked 1 Time in 1 Post
    Rep Power
    0
    So far I have .....................but it doesn't seem to be working.............If not exist c:\program files\ranger\secmon.exe then goto C:\Shutdown.exe /r

  3. #3

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,817
    Thank Post
    873
    Thanked 1,675 Times in 1,458 Posts
    Blog Entries
    12
    Rep Power
    444
    that will reboot the machine.

    If you want an imminent reboot use this. shutdown -r -f -t 0

  4. #4
    simpsonj's Avatar
    Join Date
    Apr 2009
    Location
    Oxford
    Posts
    381
    Thank Post
    159
    Thanked 64 Times in 53 Posts
    Blog Entries
    8
    Rep Power
    21
    Quote Originally Posted by noser View Post
    So far I have .....................but it doesn't seem to be working.............If not exist c:\program files\ranger\secmon.exe then goto C:\Shutdown.exe /r
    Wouldn't it be goto C:\Windows\System32\Shutdown.exe /r ? Or have you moved the Shutdown.exe?

  5. #5

    Join Date
    Dec 2007
    Posts
    83
    Thank Post
    2
    Thanked 1 Time in 1 Post
    Rep Power
    0
    Put the full path C:\Windows\System32\Shutdown.exe /r but still doesn't seem to be working...............

  6. #6
    MordyT's Avatar
    Join Date
    Sep 2012
    Location
    In a computer
    Posts
    416
    Thank Post
    43
    Thanked 66 Times in 61 Posts
    Rep Power
    18
    Instead of doing it as logon scripts, make it a bat file and call it as a log on program.

  7. #7

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,817
    Thank Post
    873
    Thanked 1,675 Times in 1,458 Posts
    Blog Entries
    12
    Rep Power
    444
    @noser please look at my post. You are doing the switches wrong.

  8. #8
    MordyT's Avatar
    Join Date
    Sep 2012
    Location
    In a computer
    Posts
    416
    Thank Post
    43
    Thanked 66 Times in 61 Posts
    Rep Power
    18
    Quote Originally Posted by FN-GM View Post
    @noser please look at my post. You are doing the switches wrong.
    Windows Vista and up you can do /r instead of -r

  9. #9

    Join Date
    Dec 2007
    Posts
    83
    Thank Post
    2
    Thanked 1 Time in 1 Post
    Rep Power
    0
    Still don't seem to be able to get it working..............any suggestions, thanks for your help so far.

  10. #10


    Join Date
    Mar 2009
    Location
    Leeds
    Posts
    6,573
    Thank Post
    228
    Thanked 851 Times in 730 Posts
    Rep Power
    294
    just run this on xp and 7 (granted as admin and by clicking not as a logon script but it worked 1st time

    if not exist c:\foo.bar shutdown -l

  11. Thanks to sted from:

    mac_shinobi (5th September 2013)

  12. #11

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,705
    Thank Post
    3,235
    Thanked 1,044 Times in 966 Posts
    Rep Power
    363
    VBS :

    Code:
    Dim objFSO, strPath
    
    strPath = "C:\FolderName"
    
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    If objFSO.FolderExists(strPath) Then
        MsgBox "The folder exists!"
    LogOff
    Else
        MsgBox "The folder doesn't exist!"
    End If
    
    Sub LogOff
    
    Set oSystems = GetObject("winmgmts:{(Shutdown)}//./root/cimv2").ExecQuery("select * from Win32_OperatingSystem where Primary=true")
    
    For Each oSystem in oSystems   
    
    'LOGOFF   = 0   
    'SHUTDOWN = 1   
    'REBOOT   = 2   
    'FORCE    = 4   
    'POWEROFF = 8   
    oSystem.Win32Shutdown 0
    Next
    
    End Sub
    Something along the line of the above, if the logoff does not work then you can either call the logoff sub ie

    Call LogOff

    Or we can get vbscript to use the command line version as suggested above by using %comspec%

    Example of using comspec in vbscript :

    Guy's Scripting Ezine 80 - VBScript Comspec Switches and CMD

    Shutdown command usage : MS-DOS shutdown command help

    To log off straight away I presume it would be shutdown /l /t 0

    Using comspec you would replace the wmi code with something like the below

    Code:
    Dim objShell
    Set objShell = CreateObject("WScript.Shell")
    objShell.Run "%comspec% /k shutdown /l /t 0"
    wscript.quit
    @Steve21 or @Arthur will most likely be able to help with cleaning the code up or even using powershell or another scripting language if vbs is not good enough ?
    Last edited by mac_shinobi; 5th September 2013 at 01:19 PM.

  13. #12

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,705
    Thank Post
    3,235
    Thanked 1,044 Times in 966 Posts
    Rep Power
    363
    Won't let me edit my above post but the script needs editing slightly as I placed the LogOff call in the wrong section of the If Statement ( so just need to move that down to the bit where it has the message box to show or say that the folder does not exist.

    Also did you need or want the script to create a directory with a specific name if it does not exist or what exactly ?

SHARE:
+ Post New Thread

Similar Threads

  1. Script to track user logins
    By Gatt in forum Scripts
    Replies: 47
    Last Post: 2nd August 2013, 10:44 AM
  2. [SIMS] Logging Users Off and Time Outs SIMS
    By Grommit in forum MIS Systems
    Replies: 27
    Last Post: 18th January 2012, 01:30 PM
  3. Replies: 4
    Last Post: 23rd November 2006, 09:33 PM
  4. Script to Create My Documents Subject Folders
    By SwedishChef in forum Scripts
    Replies: 15
    Last Post: 5th July 2006, 08:14 AM
  5. Script to change user email in AD (or Exchange)
    By SpuffMonkey in forum Scripts
    Replies: 16
    Last Post: 8th November 2005, 10:31 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
  •