return a vaule 1 when pc (user) is logged off

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

return a vaule 1 when pc (user) is logged off

15 Oct 2017, 05:13

Hii,

I have the following code which return vaule 1 when pc (user) is locked (ctrl+alt+del screen),
and return a vaule 0 when pc is open (desktop mode).

however is it possible to return a vaule 1 instead 0 also when pc is logged off (no user logged at all) ?
* i run the script remotely so i can get the vaule even with no user connected *

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.

SessionIsLocked()
{
	static WTS_CURRENT_SERVER_HANDLE := 0, WTSSessionInfoEx := 25, WTS_SESSIONSTATE_LOCK := 0x00000000, WTS_SESSIONSTATE_UNLOCK := 0x00000001 ;, WTS_SESSIONSTATE_UNKNOWN := 0xFFFFFFFF
	ret := False

	if (DllCall("ProcessIdToSessionId", "UInt", DllCall("GetCurrentProcessId", "UInt"), "UInt*", sessionId)
	 && DllCall("wtsapi32\WTSQuerySessionInformation", "Ptr", WTS_CURRENT_SERVER_HANDLE, "UInt", sessionId, "UInt", WTSSessionInfoEx, "Ptr*", sesInfo, "Ptr*", BytesReturned)) {
		SessionFlags := NumGet(sesInfo+0, 16, "Int")
		; "Windows Server 2008 R2 and Windows 7: Due to a code defect, the usage of the WTS_SESSIONSTATE_LOCK and WTS_SESSIONSTATE_UNLOCK flags is reversed."
		ret := A_OSVersion != "WIN_7" ? SessionFlags == WTS_SESSIONSTATE_LOCK : SessionFlags == WTS_SESSIONSTATE_UNLOCK
		DllCall("wtsapi32\WTSFreeMemory", "Ptr", sesInfo)
	}

	return ret
}

MsgBox % SessionIsLocked()
* tested on win 7

thanks!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: dipahk, Google [Bot] and 244 guests