Solved

Using windows logoff process with XP task scheduler logs off run as user instead of current user

Posted on 2009-07-09
8
788 Views
Last Modified: 2012-05-07
I have created a batch file which simply calls on the windows logoff.exe process located in c:\windows\system32\logoff.exe

I then created a scheduled task to call on this batch file. By default, windows scheduler pulls the currently logged on user which is fine for that profile and the batch file executes perfectly. The user is logged out and all is well.

However, this is a business environment and many users log into this PC. For security purposes we want this machine to run the logoff process if the PC has been idle for 30 minutes. All conditions such as these can be specified very easily in the windows scheduler.

Problem: The problem lies in that if a user logs in and becomes idle thereby triggering the process, the "run as" user which is a local administrator on the PC runs the process and because the process is logoff that virtual secondary logon session is terminated instead of the current user logged into the PC. I have tried running as the system account and that did not work either.

Workaround: Entering "shutdown -r" in the batch file  to reboot the PC does not log off the  user running the process thereby allowing it to work as designed. It logs of the user who is logged into the pc as I would like.

I apologize if this is wordy but if anyone has any thoughts it would be much appreciated.
0
Comment
Question by:drappl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 7

Expert Comment

by:sfarazmand
ID: 24815497
Have you tried the shutdown -l which is the log off?
0
 
LVL 1

Author Comment

by:drappl
ID: 24815539
Yes I tried that. It merely calls a different process but gives it the logoff option however it functions the same as logoff.exe.
0
 
LVL 7

Expert Comment

by:sfarazmand
ID: 24815605
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 1

Author Comment

by:drappl
ID: 24815803
After looking at the above links I have noticed they are mostly talking about writing VB Scripts which I've never done. In addition, winexit.scr is mentioned and if configured would probably work fine to log users off after 30 minutes of inactivity. The other condition which I forgot to mention was I only want this to be triggered between the hours of 8:00pm - 6:00am. I do not believe winexit has this functionality. This was the reason I was pursuing the windows scheduler route.
0
 
LVL 7

Expert Comment

by:sfarazmand
ID: 24815845
save the code as .vbs file. Then use your scheduler to run the file. That should work.
Also, using the screensaver is easier. What is the issue if it logs off after hours? No one is there, no issues, right?

' *********************************************************************** 
' * 
' * LogoffIn30 - Logs off the current user in 30 minutes 
' * John Holliday - 12/29/2005 - 1.0 
' * ChangeAuthorName - DateOfChange - IteratedVersionNumber 
' * 
' *********************************************************************** 
' 
Option Explicit 
 
Public gobjWshShell 
  
Sub ScriptInit() 
Set gobjWshShell = CreateObject("WScript.Shell") 
End Sub 
 
Function Sleep(lintNumOfSeconds, lblnUseMilliseconds) 
' Put False as the second argument to use standard seconds. 
' Put True to use milliseconds. 
If lblnUseMilliseconds = False Then 
 lintNumOfSeconds = lintNumOfSeconds * 1000 
End If 
WScript.Sleep lintNumOfSeconds 
End Function 
 
Sub ShutDown(lintShutdownType) 
Dim strComputer 
Dim OpSys 
Dim OpSysSet 
strComputer = "." 
If lintShutDownType = "" then 
 lintShutDownType = 4 
End If 
Set OpSysSet = GetObject("winmgmts:{(Debug,Shutdown)}//" & strComputer & "/root/cimv2").ExecQuery("select * from Win32_OperatingSystem where Primary=true") 
For Each OpSys in OpSysSet 
 OpSys.win32Shutdown(lintShutdownType) 
Next 
' The numbers in the Decimal column are for the lintShutDownType variable. 
' Action  Decimal  Binary 
' Logoff   0  0000 
' Reboot   2  0010 
' Force Logoff  4  0100 
' Force Reboot  6  0110 
' Powerdown   8  1000 
' Force Powerdown 12  1100 
End Sub 
 
Sub RunFor30() 
 On Error Resume Next 
Dim lblnIsDone 
Dim lintNumMinutes 
lintNumMinutes = 0 
   Do 
  lblnIsDone = False 
       Sleep 60, False 
       lintNumMinutes = lintNumMinutes + 1 
 Select Case lintNumMinutes 
  Case 25 
   gobjWshShell.Popup "Warning!" & vbCrLf & vbCrLf & "This workstaion will be logged off in 5 minutes!" & vbCrLf & "Please save your data and close any open applications." & vbCrLf & "This box will close in 15 seconds.", 15, "Logoff Warning", vbExclamation + vbOKOnly + vbSystemModal 
  Case 30 
   lblnIsDone = True 
   ShutDown 4        
  Case Else 
   ' Do nothing 
 End Select 
   Loop Until lblnIsDone = True 
End Sub 
 
' Processing starts here 
 
ScriptInit 
RunFor30 
WScript.Quit 
 
' *************** 

Open in new window

0
 
LVL 1

Accepted Solution

by:
drappl earned 0 total points
ID: 24816594
I decided to go with the "shutdown -l" command. We re-thought our circumstances and realized that a reboot in the middle of the night if our conditions are met is not a bad thing.

Thanks for your help!
0
 
LVL 7

Assisted Solution

by:sfarazmand
sfarazmand earned 250 total points
ID: 24816611
no prob. glad you got it figured out.
0
 
LVL 1

Author Comment

by:drappl
ID: 24816661
Thanks for your help.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
How to record audio from input sources to your PC – connected devices, connected preamp to record vinyl discs, streaming media, that play through your audio card: Vista, Windows 7, Windows 8, Windows 8.1 and Windows 10 – both 32 bit & 64.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question