AaronLongJBC Posted April 14, 2015 Posted April 14, 2015 I am trying to fine tune a vbs script that I am using to open a program as shell when the user logs on and to automatically log the user off when the program is closed. I have tried just setting the program as shell on the computer but it does not log off when the program is closed. This is what I have right now. Set objShell = CreateObject("WScript.Shell") strCmd = "net use Z: \\vader\adsapps\ads11_apps /persistent:yes /YES" set objExec = objShell.Exec(strCmd) set oShell=createobject("wscript.shell") sCmd="Z:\WIPT6.exe assembly-out" oShell.run sCmd,1,true 'true forces it to wait for process to finish Set OpSystems = GetObject("winmgmts:{(Shutdown)}//./root/cimv2").ExecQuery("select * from Win32_OperatingSystem where Primary=true") for each OpSys in OpSystems OpSys.Win32Shutdown 0 next sCmd="shutdown /l" oShell.run sCmd It works decently but it has some bugs that I need to work out. Mainly it is just not very reliable as when the user logs on it sometimes logs off before the program even opens. User sometimes has to log in 5 or 6 times before it works properly. I also want to eventually make the script to also log off the user after a set amount of inactivity. Any help would be nice to make it more reliable when starting up.
halbaradkenafin Posted April 14, 2015 Posted April 14, 2015 I'd probably look at finding the process name that it uses while running and checking for that as the logoff condition, that way you don't worry too much about it logging off early. I'm not sure how to do that with vbs, powershell should do it easily with Get-Process and can probably handle the rest easily enough (though may have to call the vbscript to run the app as a shell as I've never tried that in powershell). 1
AaronLongJBC Posted April 17, 2015 Author Posted April 17, 2015 (edited) I'd probably look at finding the process name that it uses while running and checking for that as the logoff condition, that way you don't worry too much about it logging off early. I'm not sure how to do that with vbs, powershell should do it easily with Get-Process and can probably handle the rest easily enough (though may have to call the vbscript to run the app as a shell as I've never tried that in powershell). Ok so this is what I have in PS. #shell.ps1 New-PSDrive -Name "Y" -PSProvider FileSystem -Root "\\vader\adsapps\ads11_apps" -Persist & 'Y:\wipt6.exe' assembly-out sleep -s 15 while(get-process wipt6.exe){sleep -s 10} & 'Y:\wipt6.exe' /terminate logoff.exe It is working for loading the program but it is killing the process and logging off while the program is still running. I'm kind of new at this so, any ideas on why? Nevermind found it. It was the .exe on the get-process. Edited April 17, 2015 by AaronLongJBC
AaronLongJBC Posted April 21, 2015 Author Posted April 21, 2015 Is there any way to also get this to logoff when the screensaver started? I tried a few things but never could get it to work.
halbaradkenafin Posted April 21, 2015 Posted April 21, 2015 Is there any way to also get this to logoff when the screensaver started? I tried a few things but never could get it to work. You can set that in group policy I believe. If you are automating this for one specific user then you can just apply the policy to a group containing that user and it won't effect anyone else.
AaronLongJBC Posted April 22, 2015 Author Posted April 22, 2015 You can set that in group policy I believe. If you are automating this for one specific user then you can just apply the policy to a group containing that user and it won't effect anyone else. I've tried setting it up through a scheduled task but I can't get it to work. Also it is running on the local computer so the remote logoff for inactivity in GPO is for terminal services only. If there is another way I haven't found it but I am a little new at this and don't know all the GPO settings. #shell.ps1New-PSDrive -Name "Y" -PSProvider FileSystem -Root "\\vader\adsapps\ads11_apps" -Persist & 'Y:\wipt.exe' assembly-out sleep -s 15 while(get-process wipt*){sleep -s 3} & 'Y:\wipt.exe' /terminate logoff.exe My setup if it helps for the whole picture is we have a plant that uses a bar code system to keep up with the different pieces as it goes through production. The computers we are going to be putting in are Windows 8.1 and they need to be locked down as much as possible. To do so I changed the shell to run powershell and the designated the script to run in a hidden window to launch the program and close when the program is closed. The data is safe from a logoff when the program is open as long as they have completed the scan process on it at the specific computer, which we already do with our TS in place, which we are wanting to get away from. I also need to be able to force a log off on the computer when inactive so that they are not in it at night when reports are ran and they need to be out for them to run. So that's some background on this if it helps. Also, our DC is a Win Server 2008.
halbaradkenafin Posted April 22, 2015 Posted April 22, 2015 You can set the screensaver to be the lock windows process/application/thing through GPO and I'd imagine it's possible to make it logoff instead. I haven't tried myself (our data security isn't that strict and staff would get very angry about it) but a few minutes in Google should reveal something for "gpo screensaver logoff" or similar.
IAMCloud_Curt Posted April 22, 2015 Posted April 22, 2015 Can't you use batch file? That's how I write scripts to open programs log off/shutdown etc..
AaronLongJBC Posted April 30, 2015 Author Posted April 30, 2015 Is there anyway I could just add it onto the powershell script I am already running.
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