Fri radikal
November 24th, 2005, 06:19 AM
Hi!
I'm making a program that will install itself as a service and will be able to detect when no one is logged in. I guess this could be done with win32 api but I can't figure out how.
/Thanks
rxbagain
November 24th, 2005, 10:01 AM
Try OpenInputDesktop and GetUserObjectInformation using UOI_USER_SID. GetUserObjectInformation will set return size to 0 if there is no user associated with the active desktop HDESK hDesk = OpenInputDesktop(0, FALSE, DESKTOP_READOBJECTS);
if (hDesk) {
SID sid;
DWORD dwSidLength = 0;
BOOL bSuccess = GetUserObjectInformation(hDesk, UOI_USER_SID, &sid, sizeof(SID), &dwSidLength);
if (!bSuccess && ERROR_INSUFFICIENT_BUFFER == GetLastError()) {
SID *psid = (SID*)malloc(dwSidLength);
if (psid) {
bSuccess = GetUserObjectInformation(hDesk, UOI_USER_SID, psid, dwSidLength, &dwSidLength);
free(psid);
}
}
if (bSuccess) {
if (dwSidLength) {
// a user has loged on
}
else {
// no user
}
}
CloseDesktop(hDesk);
}Or you can try UOI_NAME parameter. It will be "Winlogon" if the desktop is the logon screen. I'm not sure though if that's the name for all versions.
Hope it will help you.