noah Posted September 3, 2013 Posted September 3, 2013 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
noah Posted September 3, 2013 Author Posted September 3, 2013 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
FN-GM Posted September 3, 2013 Posted September 3, 2013 that will reboot the machine. If you want an imminent reboot use this. shutdown -r -f -t 0
simpsonj Posted September 3, 2013 Posted September 3, 2013 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?
noah Posted September 3, 2013 Author Posted September 3, 2013 Put the full path C:\Windows\System32\Shutdown.exe /r but still doesn't seem to be working...............
MordyT Posted September 3, 2013 Posted September 3, 2013 Instead of doing it as logon scripts, make it a bat file and call it as a log on program.
FN-GM Posted September 3, 2013 Posted September 3, 2013 @noser please look at my post. You are doing the switches wrong.
MordyT Posted September 3, 2013 Posted September 3, 2013 @noser please look at my post. You are doing the switches wrong. Windows Vista and up you can do /r instead of -r
noah Posted September 5, 2013 Author Posted September 5, 2013 Still don't seem to be able to get it working..............any suggestions, thanks for your help so far.
sted Posted September 5, 2013 Posted September 5, 2013 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 1
mac_shinobi Posted September 5, 2013 Posted September 5, 2013 (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 September 5, 2013 by mac_shinobi
mac_shinobi Posted September 5, 2013 Posted September 5, 2013 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 ?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now