Ravel Posted October 28, 2008 Share Posted October 28, 2008 Can anyone help me with the following script. I am trying to use this to run a screensaver after the computer has been idle for a set amount of time. After that set amount of time it starts the screensaver.... what I would like it to do also is when i return to the computer to and move the mouse or press a key it automatically locks the PC. This is for windows vista if that helps. Thanks for the help. expandcollapse popupGlobal $fLocked = False HotKeySet("{ESC}", "_Quit") While 1 If _Timer_GetIdleTime() = 10000 Then Run ("C:\Users\ATCALS Maintenance\Desktop\Converter.exe"); run screensaver EndIf if _Timer_GetIdleTime() < 10000 Then ProcessWait ("Converter.exe") tooltip ("test"); Lock console EndIf Sleep(100) WEnd Func _Timer_GetIdleTime() ; Get ticks at last activity Local $tStruct = DllStructCreate("uint;dword"); DllStructSetData($tStruct, 1, DllStructGetSize($tStruct)); DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($tStruct)) ; Get current ticks since last restart Local $avTicks = DllCall("Kernel32.dll", "int", "GetTickCount") ; Return time since last activity, in ticks (approx milliseconds) Local $iDiff = $avTicks[0] - DllStructGetData($tStruct, 2) If $iDiff >= 0 Then ; Normal return Return $iDiff Else ; Rollover of ticks counter has occured Return SetError(0, 1, $avTicks[0]) EndIf EndFunc ;==>_Timer_GetIdleTime Func _Quit() Exit EndFunc Link to comment Share on other sites More sharing options...
monoceres Posted October 28, 2008 Share Posted October 28, 2008 Hi! Use ProcessClose() to exit the screensaver and then you can use this line to lock the workstation. DllCall("User32.dll","none","LockWorkStation") Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
Ravel Posted October 28, 2008 Author Share Posted October 28, 2008 Hi!Use ProcessClose() to exit the screensaver and then you can use this line to lock the workstation.DllCall("User32.dll","none","LockWorkStation")Thanks I dont think thought that that will work because I want this to be automatic. I dont need to close the screensaver it will do that itself automatically. I just need to have the screensaver start automatically when the pc is idle... i.e. no key or mouse movement... and then when the mouse is moved or a key is pressed the computer automatically locks. Link to comment Share on other sites More sharing options...
monoceres Posted October 28, 2008 Share Posted October 28, 2008 Just minor adjustments. expandcollapse popupGlobal $fLocked = False Global $Tick HotKeySet("{ESC}", "_Quit") While 1 If _Timer_GetIdleTime() > 10000 Then Run ("C:\Users\ATCALS Maintenance\Desktop\Converter.exe"); run screensaver $tick=_Timer_GetIdleTime() EndIf if _Timer_GetIdleTime() < $tick And ProcessExists("converter.exe") Then ProcessWait ("Converter.exe") tooltip ("test"); Lock console DllCall("User32.dll","none","LockWorkStation") EndIf Sleep(100) WEnd Func _Timer_GetIdleTime() ; Get ticks at last activity Local $tStruct = DllStructCreate("uint;dword"); DllStructSetData($tStruct, 1, DllStructGetSize($tStruct)); DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($tStruct)) ; Get current ticks since last restart Local $avTicks = DllCall("Kernel32.dll", "int", "GetTickCount") ; Return time since last activity, in ticks (approx milliseconds) Local $iDiff = $avTicks[0] - DllStructGetData($tStruct, 2) If $iDiff >= 0 Then ; Normal return Return $iDiff Else ; Rollover of ticks counter has occured Return SetError(0, 1, $avTicks[0]) EndIf EndFunc ;==>_Timer_GetIdleTime Func _Quit() Exit EndFunc Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
Ravel Posted October 28, 2008 Author Share Posted October 28, 2008 Just minor adjustments. expandcollapse popupGlobal $fLocked = False Global $Tick HotKeySet("{ESC}", "_Quit") While 1 If _Timer_GetIdleTime() > 10000 Then Run ("C:\Users\ATCALS Maintenance\Desktop\Converter.exe"); run screensaver $tick=_Timer_GetIdleTime() EndIf if _Timer_GetIdleTime() < $tick And ProcessExists("converter.exe") Then ProcessWait ("Converter.exe") tooltip ("test"); Lock console DllCall("User32.dll","none","LockWorkStation") EndIf Sleep(100) WEnd Func _Timer_GetIdleTime() ; Get ticks at last activity Local $tStruct = DllStructCreate("uint;dword"); DllStructSetData($tStruct, 1, DllStructGetSize($tStruct)); DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($tStruct)) ; Get current ticks since last restart Local $avTicks = DllCall("Kernel32.dll", "int", "GetTickCount") ; Return time since last activity, in ticks (approx milliseconds) Local $iDiff = $avTicks[0] - DllStructGetData($tStruct, 2) If $iDiff >= 0 Then ; Normal return Return $iDiff Else ; Rollover of ticks counter has occured Return SetError(0, 1, $avTicks[0]) EndIf EndFunc;==>_Timer_GetIdleTime Func _Quit() Exit EndFunc K cool. that converter.exe is pretty much a place holder. What I have been having trouble with is finding out what the actual process name is for the screensaver. Because the process only exists when the screensaver is active, but of course in order to see the process I have to deactivate the screensaver. Do you have any ideas on how to determine the process? Is it just the name of the screensaver? The name is photoscreensaver.scr. Link to comment Share on other sites More sharing options...
monoceres Posted October 28, 2008 Share Posted October 28, 2008 K cool. that converter.exe is pretty much a place holder. What I have been having trouble with is finding out what the actual process name is for the screensaver. Because the process only exists when the screensaver is active, but of course in order to see the process I have to deactivate the screensaver. Do you have any ideas on how to determine the process? Is it just the name of the screensaver? The name is photoscreensaver.scr.Yep, it's photoscreensaver.scr Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
Ravel Posted October 28, 2008 Author Share Posted October 28, 2008 Yep, it's photoscreensaver.scrCool I will test it out. Thanks. Link to comment Share on other sites More sharing options...
Ravel Posted October 28, 2008 Author Share Posted October 28, 2008 (edited) Cool I will test it out. Thanks.Ok I tried testing it, but the screensaver started but then quit and when right to locking the pc. So I must be missing something here. It also just continued opening the screensaver repeatedly and almost locked up the pc. Edited October 28, 2008 by Ravel Link to comment Share on other sites More sharing options...
Ravel Posted October 28, 2008 Author Share Posted October 28, 2008 (edited) Ok I tried testing it, but the screensaver started but then quit and when right to locking the pc. So I must be missing something here. I think the issue is in this line where it is looking for the idletick... What I want is to have the screensaver run until a key is pressed or the mouse is moved. If neither is interacted with then the screensaver should keep going. ie the script is paused i guess. if _Timer_GetIdleTime() < $tick And ProcessExists("PhotoScreensaver.scr") Then ProcessWait ("PhotoScreensaver.scr") tooltip ("test"); Lock console Maybe it isnt recognizing the processwait command? if photoscreensaver.scr isnt the actual process then the processwait is probably not working. The problem is I dont know how to verify the process name. Edited October 28, 2008 by Ravel Link to comment Share on other sites More sharing options...
Ravel Posted October 28, 2008 Author Share Posted October 28, 2008 I wonder is there a way to set this up to were the script just pauses until the computer is "no longer idle" and then lock. That way just forgoing the processwait command altogether since I cannot verify the process that is running. Link to comment Share on other sites More sharing options...
monoceres Posted October 28, 2008 Share Posted October 28, 2008 I wonder is there a way to set this up to were the script just pauses until the computer is "no longer idle" and then lock. That way just forgoing the processwait command altogether since I cannot verify the process that is running. You mean something like this: Global $oldtick=_Timer_GetIdleTime() Global $newtick=0 While Sleep(25) $newtick=_Timer_GetIdleTime() If $newtick<$oldtick Then ExitLoop $oldtick=$newtick WEnd DllCall("User32.dll","none","LockWorkStation") Func _Timer_GetIdleTime() ; Get ticks at last activity Local $tStruct = DllStructCreate("uint;dword"); DllStructSetData($tStruct, 1, DllStructGetSize($tStruct)); DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($tStruct)) ; Get current ticks since last restart Local $avTicks = DllCall("Kernel32.dll", "int", "GetTickCount") ; Return time since last activity, in ticks (approx milliseconds) Local $iDiff = $avTicks[0] - DllStructGetData($tStruct, 2) If $iDiff >= 0 Then ; Normal return Return $iDiff Else ; Rollover of ticks counter has occured Return SetError(0, 1, $avTicks[0]) EndIf EndFunc;==>_Timer_GetIdleTime Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
Ravel Posted October 28, 2008 Author Share Posted October 28, 2008 You mean something like this: Global $oldtick=_Timer_GetIdleTime() Global $newtick=0 While Sleep(25) $newtick=_Timer_GetIdleTime() If $newtick<$oldtick Then ExitLoop $oldtick=$newtick WEnd DllCall("User32.dll","none","LockWorkStation") Func _Timer_GetIdleTime() ; Get ticks at last activity Local $tStruct = DllStructCreate("uint;dword"); DllStructSetData($tStruct, 1, DllStructGetSize($tStruct)); DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($tStruct)) ; Get current ticks since last restart Local $avTicks = DllCall("Kernel32.dll", "int", "GetTickCount") ; Return time since last activity, in ticks (approx milliseconds) Local $iDiff = $avTicks[0] - DllStructGetData($tStruct, 2) If $iDiff >= 0 Then ; Normal return Return $iDiff Else ; Rollover of ticks counter has occured Return SetError(0, 1, $avTicks[0]) EndIf EndFunc;==>_Timer_GetIdleTime That looks like what I am referring to. Let me try it out... Ill let you know... Link to comment Share on other sites More sharing options...
Ravel Posted October 28, 2008 Author Share Posted October 28, 2008 (edited) That looks like what I am referring to. Let me try it out... Ill let you know... K I looked at the last one... and when I move the mouse it locks... good. thats what I want for that end. Now what I would like to do is have that same ending... only the script will run continuously.... starting the screensaver every time the PC is idle for a predetermined amount of time. then upon moving mouse or pressing the key board the script then sends the command to lock the pc. If the PC is locked the script stays in a paused state until I unlock it at which time it would go back to the beginning and start the process over. I am not sure if using something like the following code can work in this situation. I am in the realm of not really understanding how to get these things to work together. Please let me know if you understand what I am referring to (disregard the "messages" i dont need those this is an excerpt from another script) While 1 Sleep(1000) If _isWorksatationLocked() Then ConsoleWrite(@HOUR & ":" & @MIN & ":" & @SEC & " - " & "workstation locked" & @CRLF) WEnd Func _isWorksatationLocked() If StringInStr(WinGetText(""), "Program Manager") <> 0 And WinGetTitle("") = "" Then Return 1 Return 0 EndFunc;==>_isWorksatationLocked This way if it senses the workstation is locked... it can pause the script until the workstation is unlocked and resume at the beginning waiting again for the computer to be idle and then -----> start screensaver------> wait for movement/keypress ------> if movement found i.e. no longer idle------> lock workstation-----> wait for workstation to become unlocked-----> start over. This um is basically away to sercumvent the locked windows version screensaver that is currently the default for my work PC. This would allow me to use my own screensaver/lock mechanism and actually adjust the timers. Because We cant do that at work. Edited October 28, 2008 by Ravel Link to comment Share on other sites More sharing options...
FreeFry Posted October 28, 2008 Share Posted October 28, 2008 Perhaps this is what you want? While Sleep(250) $idleTime = _Timer_GetIdleTime() If $idleTime >= 5000 Then ShellExecuteWait(@SystemDir & "\logon.scr") DllCall("User32.dll","none","LockWorkStation") EndIf WEnd Func _Timer_GetIdleTime() ; Get ticks at last activity Local $tStruct = DllStructCreate("uint;dword"); DllStructSetData($tStruct, 1, DllStructGetSize($tStruct)); DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($tStruct)) ; Get current ticks since last restart Local $avTicks = DllCall("Kernel32.dll", "int", "GetTickCount") ; Return time since last activity, in ticks (approx milliseconds) Local $iDiff = $avTicks[0] - DllStructGetData($tStruct, 2) If $iDiff >= 0 Then ; Normal return Return $iDiff Else ; Rollover of ticks counter has occured Return SetError(0, 1, $avTicks[0]) EndIf EndFunc;==>_Timer_GetIdleTime Link to comment Share on other sites More sharing options...
Ravel Posted October 28, 2008 Author Share Posted October 28, 2008 (edited) Wont that code send the lock as well as start the screensaver, after the prescribed idle time has elapsed, at the same time? I think that is what I am interpreting from the code... Thats not how I want it to work.... I would like the screensaver to run until the system is no longer idle.... ie a key or button press and then the script.... sensing that.... sends the lock command.*EDIT*um wait let me see I just noticed that it was shellexecutewait and not just shellexecute. Let me try and get back to you. Edited October 28, 2008 by Ravel Link to comment Share on other sites More sharing options...
FreeFry Posted October 28, 2008 Share Posted October 28, 2008 It will not lock until the screen saver exits, ie. when you move the mouse or push a button. Link to comment Share on other sites More sharing options...
Ravel Posted October 28, 2008 Author Share Posted October 28, 2008 (edited) It will not lock until the screen saver exits, ie. when you move the mouse or push a button. Cool yea that is what I realized after I saw the wait portion of the command. it worked like a charm... the only other question I had was that can i get this to recognize when the mouse is moved and then immediately send the lock command? I should add that this is the google screensaver which allows you to move the mouse and the screensaver doesnt shut off, however you can use the mouse to click exit screensaver which would then allow you to gain access to the pc Edited October 28, 2008 by Ravel Link to comment Share on other sites More sharing options...
Ravel Posted October 28, 2008 Author Share Posted October 28, 2008 (edited) Cool yea that is what I realized after I saw the wait portion of the command. it worked like a charm... the only other question I had was that can i get this to recognize when the mouse is moved and then immediately send the lock command? I should add that this is the google screensaver which allows you to move the mouse and the screensaver doesnt shut off, however you can use the mouse to click exit screensaver which would then allow you to gain access to the pc this is what I have cobbled together: expandcollapse popupGlobal $Tick HotKeySet("{ESC}", "_Quit") While Sleep(250) $idleTime = _Timer_GetIdleTime() If $idleTime >= 5000 Then ShellExecuteWait(@SystemDir & "\PhotoScreensaver.scr"); run screensaver $tick=_Timer_GetIdleTime() EndIf if _Timer_GetIdleTime() < $tick And ProcessExists("PhotoScreensaver.scr") Then ProcessWait ("PhotoScreensaver.scr") tooltip ("console locked"); Lock console DllCall("User32.dll","none","LockWorkStation") EndIf Sleep(100) WEnd Func _Timer_GetIdleTime() ; Get ticks at last activity Local $tStruct = DllStructCreate("uint;dword"); DllStructSetData($tStruct, 1, DllStructGetSize($tStruct)); DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($tStruct)) ; Get current ticks since last restart Local $avTicks = DllCall("Kernel32.dll", "int", "GetTickCount") ; Return time since last activity, in ticks (approx milliseconds) Local $iDiff = $avTicks[0] - DllStructGetData($tStruct, 2) If $iDiff >= 0 Then ; Normal return Return $iDiff Else ; Rollover of ticks counter has occured Return SetError(0, 1, $avTicks[0]) EndIf EndFunc;==>_Timer_GetIdleTime Func _Quit() Exit EndFunc I havent tested was wondering if you can look it over first. Although I am not sure if the screensaver process actually shows up as "photoscreensaver.scr" if it doesnt then it wont matter about the processwait or processexist commands right? Edited October 28, 2008 by Ravel Link to comment Share on other sites More sharing options...
Ravel Posted October 28, 2008 Author Share Posted October 28, 2008 I didnt use the #include timers, so I am not sure if $tick will work... maybe I need include timers.au3 and take out the func _timer... Link to comment Share on other sites More sharing options...
Ravel Posted October 28, 2008 Author Share Posted October 28, 2008 Ok this worked the way it wanted it to: expandcollapse popupHotKeySet("{Esc}", "_Quit") Global $oldtick=_Timer_GetIdleTime() Global $newtick=0 While Sleep(250) $idleTime = _Timer_GetIdleTime() If $idleTime >= 5000 Then ShellExecuteWait(@SystemDir & "\PhotoScreensaver.scr") DllCall("User32.dll","none","LockWorkStation") EndIf $newtick=_Timer_GetIdleTime() If $newtick<$oldtick Then $oldtick=$newtick EndIf WEnd DllCall("User32.dll","none","LockWorkStation") Func _Timer_GetIdleTime() ; Get ticks at last activity Local $tStruct = DllStructCreate("uint;dword"); DllStructSetData($tStruct, 1, DllStructGetSize($tStruct)); DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($tStruct)) ; Get current ticks since last restart Local $avTicks = DllCall("Kernel32.dll", "int", "GetTickCount") ; Return time since last activity, in ticks (approx milliseconds) Local $iDiff = $avTicks[0] - DllStructGetData($tStruct, 2) If $iDiff >= 0 Then ; Normal return Return $iDiff Else ; Rollover of ticks counter has occured Return SetError(0, 1, $avTicks[0]) EndIf EndFunc;==>_Timer_GetIdleTime Func _Quit() Exit EndFunc Thanks for everyones help! Link to comment Share on other sites More sharing options...
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