Miranda NG Official Community Forum

Forum for English speaking Miranda NG users => Development => Topic started by: MVV on 14 08 2014, 09:13:41

Title: Lock workstation detection and UAC
Post by: MVV on 14 08 2014, 09:13:41
It seems that IsWorkstationLocked function (src\mir_core\winver.cpp) wasn't updated a while ago because it reports lock when UAC confirmations pop up. As a consequence, it causes false lock detects e.g. in AdvancedAutoAway plugin which changes status on every UAC confirmation.

AFAIK Windows switches to safe desktop when UAC confirmation pops up, so it causes false detect with current (https://github.com/miranda-ng/miranda-ng/blob/f7bf9527ede3193cfdfd9e30a7a0f20e9a2bf604/src/mir_core/winver.cpp) IsWorkstationLocked implementation:
IsWorkstationLocked
Code: [Select]
MIR_CORE_DLL(BOOL) IsWorkstationLocked(void)
{
HDESK hDesk = OpenInputDesktop(0, FALSE, DESKTOP_SWITCHDESKTOP);
if (hDesk == NULL)
return true;

TCHAR tszName[100];
DWORD cbName;
BOOL bLocked = (!GetUserObjectInformation(hDesk, UOI_NAME, tszName, SIZEOF(tszName), &cbName) || lstrcmpi(tszName,_T("default")) != 0);
CloseDesktop(hDesk);
return bLocked;
}
[close]
Title: Re: Lock workstation detection and UAC
Post by: Wishmaster on 14 08 2014, 09:31:33
Hi,
Could you provide a patch for it? :)
Title: Re: Lock workstation detection and UAC
Post by: MVV on 18 08 2014, 12:04:51
I can't say about exact patch but here is a working solution (found here (http://stackoverflow.com/questions/4260878/openinputdesktop-to-determine-secure-login-desktop) and tested by myself). Unfortunately it is not the call-to-get-answer one, it requires a window message processing.

We need to register main Miranda window for WM_WTSSESSION_CHANGE notifications using WTSRegisterSessionNotification function. Then we need to set a lock flag when OS reports that workstation is locked/unlocked. All notifications that are sent with this message are listed here (http://msdn.microsoft.com/en-us/library/aa383828.aspx). We are interested in two ones: wParam==WTS_SESSION_LOCK and wParam==WTS_SESSION_UNLOCK. So, fixed IsWorkstationLocked should simply return this flag state (it may simply be a static variable in winver.cpp source file).

I tried some things with OpenInputDesktop function but it returns ERROR_ACCESS_DENIED on both lock and UAC prompt.