Jump to content

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


Recommended Posts

Posted

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

Posted
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
Posted
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?

Posted

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

  • Thanks 1
Posted (edited)

VBS :

 


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

[color=#00008B]Set[/color] oSystems = GetObject([color=#800000]"winmgmts:{(Shutdown)}//./root/cimv2"[/color]).ExecQuery([color=#800000]"select * from Win32_OperatingSystem where Primary=true"[/color])
[color=#00008B]
For[/color] [color=#00008B]Each[/color] oSystem [color=#00008B]in[/color] oSystems   

[color=gray]'LOGOFF   = 0[/color]   
[color=gray]'SHUTDOWN = 1[/color]   
[color=gray]'REBOOT   = 2[/color]   
[color=gray]'FORCE    = 4[/color]   
[color=gray]'POWEROFF = 8[/color]   
oSystem.Win32Shutdown [color=#800000]0
[/color][color=#00008B]Next
[/color]
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

 

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 ?

Edited by mac_shinobi
Posted

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 ?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...