Jump to content

Screensaver + lock help


Ravel
 Share

Recommended Posts

What is the $oldtick, $newtick stuff supposed to do? Looks just like redundant code. :P

And the DllCall("User32.dll","none","LockWorkStation") below your WEnd will never be called, as the loop will never end.

Basically you've just added code that does nothing to the example I posted(except for the HotKeySet). :|

Edited by FreeFry
Link to comment
Share on other sites

What is the $oldtick, $newtick stuff supposed to do? Looks just like redundant code. :P

And the DllCall("User32.dll","none","LockWorkStation") below your WEnd will never be called, as the loop will never end.

Basically you've just added code that does nothing to the example I posted(except for the HotKeySet). :|

i dont want the loop to end. I want it to continue. I just want it to lock the pc and when I come back I unlock the pc and it waits for the pc to become idle again and then it will lock.... a continuous loop is what I was looking for. Check it out for yourself... you will see what I was referring too. the old tick and new tick are to start the timer on how long the pc has been idle since the screensaver has been activated. Not because once the screensaver has been activated the computer is in a idle state. when I come back and move the mouse or press a button the computer is no longer idle and then locks... basically making sure that my computer is secured.

Link to comment
Share on other sites

That's what I'm saying, your loop will never end, ie. it will never run DllCall("User32.dll","none","LockWorkStation") which is below your WEnd.

And the $newtick and $oldtick is never used for anything, you only check if $newtick is below $oldtick, but you never take any action based on that.

This:

HotKeySet("{Esc}", "_Quit")

While Sleep(250)
    $idleTime = _Timer_GetIdleTime()
    If $idleTime >= 5000 Then
        ShellExecuteWait(@SystemDir & "\PhotoScreensaver.scr")
        DllCall("User32.dll","none","LockWorkStation")
    EndIf
WEnd

Would be the same as what you have now:

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")

You do not "start" this timer. This timer is an internal timer in windows, and is always active.

When you call it, you receive the amount of milliseconds that the os haven't recieved an input(from mouse, keyboard, etc.).

ShellExecuteWait will run the screensaver, then do nothing until the screensaver exits(ie. when you move your mouse/press a button), then it will instantly lock the computer, and start the loop all over again.

Edited by FreeFry
Link to comment
Share on other sites

That's what I'm saying, your loop will never end, ie. it will never run DllCall("User32.dll","none","LockWorkStation") which is below your WEnd.

And the $newtick and $oldtick is never used for anything, you only check if $newtick is below $oldtick, but you never take any action based on that.

This:

HotKeySet("{Esc}", "_Quit")

While Sleep(250)
    $idleTime = _Timer_GetIdleTime()
    If $idleTime >= 5000 Then
        ShellExecuteWait(@SystemDir & "\PhotoScreensaver.scr")
        DllCall("User32.dll","none","LockWorkStation")
    EndIf
WEnd

Would be the same as what you have now:

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")

You do not "start" this timer. This timer is an internal timer in windows, and is always active.

When you call it, you receive the amount of milliseconds that the os haven't received an input(from mouse, keyboard, etc.).

ShellExecuteWait will run the screensaver, then do nothing until the screensaver exits(ie. when you move your mouse/press a button), then it will instantly lock the computer, and start the loop all over again.

Yes I understand everything that you are saying. But what I am trying to explain is that I used the example code you provided, and it did not do what I wanted it to do. It did not respond the way you are saying. When the code was run it immediately locked the PC if the dllcall was inside the loop. If I placed it outside the loop it ran the screensaver and then when I pressed a button it locked the PC. But it would then end the script, and I would have to restart the script. The way that it is written the way I had it, it worked the way I wanted. The way I explained before. I am not saying your way didn't work... It did, but it was not the outcome that I wanted. It helped me arrive at the outcome that I wanted which is what i think the point of all of this is right?
Link to comment
Share on other sites

  • 6 months later...

All I really wanted was the lock workstation command, got it thanks :)

But is there a way to determine if the computer is at the unlock screen or the initial logon screen?

I want my script to sit idle unless someone is logged in and the computer is unlocked.

Thanks,

Kenny

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...