Jump to content
Sign in to follow this  
Ravel

Screensaver + lock help

Recommended Posts

Ravel

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.

Global $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

Share this post


Link to post
Share on other sites
monoceres

Hi!

Use ProcessClose() to exit the screensaver and then you can use this line to lock the workstation.

DllCall("User32.dll","none","LockWorkStation")

:P


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
Ravel

Hi!

Use ProcessClose() to exit the screensaver and then you can use this line to lock the workstation.

DllCall("User32.dll","none","LockWorkStation")

:P

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.

Share this post


Link to post
Share on other sites
monoceres

Just minor adjustments.

Global $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!

Share this post


Link to post
Share on other sites
Ravel

Just minor adjustments.

Global $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.

Share this post


Link to post
Share on other sites
monoceres

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!

Share this post


Link to post
Share on other sites
Ravel

Yep, it's photoscreensaver.scr

Cool I will test it out. Thanks.

Share this post


Link to post
Share on other sites
Ravel

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 by Ravel

Share this post


Link to post
Share on other sites
Ravel

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 by Ravel

Share this post


Link to post
Share on other sites
Ravel

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.

Share this post


Link to post
Share on other sites
monoceres

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

:P


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
Ravel

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

:P

That looks like what I am referring to. Let me try it out... Ill let you know...

Share this post


Link to post
Share on other sites
Ravel

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 by Ravel

Share this post


Link to post
Share on other sites
FreeFry

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

Share this post


Link to post
Share on other sites
Ravel

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 by Ravel

Share this post


Link to post
Share on other sites
FreeFry

It will not lock until the screen saver exits, ie. when you move the mouse or push a button. :P

Share this post


Link to post
Share on other sites
Ravel

It will not lock until the screen saver exits, ie. when you move the mouse or push a button. :P

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 by Ravel

Share this post


Link to post
Share on other sites
Ravel

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:

Global $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 by Ravel

Share this post


Link to post
Share on other sites
Ravel

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...

Share this post


Link to post
Share on other sites
Ravel

Ok this worked the way it wanted it to:

HotKeySet("{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!

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.