AutoHotkey Community

It is currently May 27th, 2012, 10:11 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: August 4th, 2006, 10:09 am 
I got the function "LockWorkStation" when searching for a solution of how to lock the system:[MSDN:LockWorkStation]
And it says:
Quote:
There is no function you can call to determine whether the workstation is locked. To verify whether it is worth attempting to update your user interface, you can test whether or not your window is visible.


So, I wrote a GUI script for testing, but not works:
Code:
; Press [F12] to lock your system, waits about 3+ seconds and unlock it.
; Then press [F10] to check if system has ever been locked (hope so).
Gui, Show, w400 h300, Test
SysLocked = Unlocked
Return

GuiClose:
ExitApp

F12::
    Result := DllCall("LockWorkStation", "str", "User32.dll")
    Goto, TestWin
Return

TestWin:
    Sleep, 3000
    WinGet, Style, Style, Test ahk_class AutoHotkeyGUI
    If !(Style & 0x10000000)  ; 0x10000000 is WS_VISIBLE
         SysLocked = Locked
Return

F10::MsgBox %SysLocked%

#x::ExitApp


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 4th, 2006, 10:25 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Dear Friend, :)

These are two ways to programmatically Lock Workstation:

Code:
Run,%A_WinDir%\System32\Rundll32.exe User32.dll`,LockWorkStation


Code:
DllCall("LockWorkStation")


Adapt any of the above and test your code.

Regards, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 4th, 2006, 10:32 am 
Goyyah wrote:
Dear Friend, :)

These are two ways to programmatically Lock Workstation:



Thank you my dear Goyyah.
But I am NOT asking how to lock the system (I know how :wink: ), I am now asking how to determine whether the workstation is locked. :(


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 4th, 2006, 11:12 am 
I am now searching the whole INTERNET.. :twisted:


Report this post
Top
  
Reply with quote  
PostPosted: August 4th, 2006, 2:04 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Code:
    Result := DllCall("LockWorkStation", "str", "User32.dll")


Ok! I thought that would not work, but it does! You have your own way of DllCall!

Regards, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
PostPosted: August 4th, 2006, 2:21 pm 
Goyyah wrote:
Code:
    Result := DllCall("LockWorkStation", "str", "User32.dll")


Ok! I thought that would not work, but it does! You have your own way of DllCall!

Regards, :)


Oops! Maybe you're right, but that's not the point.
I replace
Code:
Result := DllCall("LockWorkStation", "str", "User32.dll")
to
Code:
DllCall("LockWorkStation")
, but it seems that still not works (at least not work on my pc)!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 4th, 2006, 2:24 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
I confirm!
Code:
DllCall("LockWorkStation")

is correct & should work.

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 4th, 2006, 2:34 pm 
Goyyah wrote:
I confirm!
Code:
DllCall("LockWorkStation")

is correct & should work.


Oops!...again :shock:

Yes, the DllCall works indeed( it do lock my system ). But, the point is:
Quote:
I am NOT asking how to lock the system (I know how ), I am now asking how to determine whether the workstation is locked.


Anyway, I have do a search on the whole INTERNET :P and I find that this is not a easy task. [/b]


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 4th, 2006, 2:36 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Try the following (works for me):

Code:
; Press [F12] to lock your system, waits about 3+ seconds and unlock it.
; Then press [F10] to check if system has ever been locked (hope so).

Gui, Show, w400 h300, Test
SysLocked = Unlocked
Return

GuiClose:
ExitApp

F12::
DllCall("LockWorkStation")
Goto, TestWin
Return

TestWin:
Sleep, 3000
ID := WinExist("A")
IfEqual,ID,0, SetEnv,SysLocked,Locked
Return

F10::MsgBox %SysLocked%

#x::ExitApp


Tell me If it works for you too!

Regards, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 4th, 2006, 2:40 pm 
If we could find a good way to detect the system's status(lock/unlock), it maybe useful for us to create a script that would do something interesting once the system was locked.

BTW, I found this article that maybe useful (VB stuffs...I am not similar with :evil: ):

http://www.inquiry.com/techtips/nt_pro/ ... NT0701.asp


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 4th, 2006, 2:42 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Do you try the modified version of your code I posted ??

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 4th, 2006, 2:51 pm 
Offline

Joined: December 7th, 2005, 8:29 am
Posts: 345
maybe if can tell the script to find the color of somthing that was on the desktop?

maybe the start button XP flag or somthing else, if he cant find it , then workstation is locked.

hope that helps, cause when you look the pc the screen changes.

Twhyman


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 4th, 2006, 2:56 pm 
Goyyah wrote:
Do you try the modified version of your code I posted ??


Thanks for your reply, Goyyah :D I did not see your post because of the delay.

I try your code and it seems that it works! Wow! :wink:
Could you make a explanation for your code:
Code:
ID := WinExist("A")
IfEqual,ID,0, SetEnv,SysLocked,Locked

:?:
Why could you ensure that the system is being locked if ID = 0 ?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 4th, 2006, 2:57 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
twhyman wrote:
maybe if can tell the script to find the color of somthing that was on the desktop?


Code:
ID := WinExist("A")
IfEqual,ID,0, ....


The above would suffice!
It is because a different desktop is used/shown when the Workstation is locked.
So WinExist("A") would return 0x0, because it cannot retrieve the handle to the Window (that is shown) when locked!

Hope I was clear.

Regards, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 4th, 2006, 3:01 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Blablabla wrote:
Could you make a explanation for your code:


I have already explained ... still

WinExist("A") returns the ahk_id of the active window.
When locked you cannot retrieve the ahk_id of the active window.
WinExist("A") would return 0x0 which should help us to determine whether the station is locked.

Hope I was clear on that.

Regards, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], BrandonHotkey, Maestr0 and 62 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group