How to know if there is a valid session running on the machine or not ?
-
Hello All, I have a service and I want to spawn a process through it but only at the time when I found no user logged on to the machine. i.e I have a function which is executed on a timely basis and it should check the number of active user sessions on that machine and if the count comes to be zero it should spawn the process in system account . Regards, Kushagra
-
Hi Kushagra, You could use the NetWkstaUserEnum Function[^] to enumerate logged on users. Best Wishes, -David Delaune
Thanks man , That is waht I was looking for :) Kushagra
-
Hi Kushagra, You could use the NetWkstaUserEnum Function[^] to enumerate logged on users. Best Wishes, -David Delaune
NetWkstaUserEnum The NetWkstaUserEnum function lists information about all users currently logged on to the workstation. This list includes interactive, service and batch logons. I want only the list of interactive users and not service and batch logons , can you please let me know the way to do it ???
-
Thanks man , That is waht I was looking for :) Kushagra
Beside the solution provided by the poster before, here is an alternative idea. Catch the SERVICE_CONTROL_SESSIONCHANGE event in your service (only with HandlerEx possible). This event is triggered every time a user logs on / logs off / remote log on / remote log off etc. Combined with the solution before you will be able to start your app at the log off of the last user and stops or pauses if an user logs in. Greetings Covean
-
NetWkstaUserEnum The NetWkstaUserEnum function lists information about all users currently logged on to the workstation. This list includes interactive, service and batch logons. I want only the list of interactive users and not service and batch logons , can you please let me know the way to do it ???
-
Maybe try for every logged-in-user you enumurate NetUserGetInfo with level 23 where flag is UF_NORMAL_ACCOUNT.
-
Maybe try for every logged-in-user you enumurate NetUserGetInfo with level 23 where flag is UF_NORMAL_ACCOUNT.
Can you explain this with an example ? My goal is simple I want to count the number of active sessions on a server or machine which will be my own base machine , if count comes 0 I will execute my script else I wont. Kushagra
-
NetWkstaUserEnum The NetWkstaUserEnum function lists information about all users currently logged on to the workstation. This list includes interactive, service and batch logons. I want only the list of interactive users and not service and batch logons , can you please let me know the way to do it ???
If you need to filter out the remote sessions then you will be better off using: LsaEnumerateLogonSessions Function[^] to enumerate the sessions. You will then need to use the LsaGetLogonSessionData Function[^] to populate a SECURITY_LOGON_SESSION_DATA Structure[^] and check for LogonType of RemoteInteractive. You should filter out types except Interactive. Best Wishes, -David Delaune
-
How is that suppose to work? Nearly all user accounts are UF_NORMAL_ACCOUNT regardless of session ID. Best Wishes, -David Delaune
-
If you need to filter out the remote sessions then you will be better off using: LsaEnumerateLogonSessions Function[^] to enumerate the sessions. You will then need to use the LsaGetLogonSessionData Function[^] to populate a SECURITY_LOGON_SESSION_DATA Structure[^] and check for LogonType of RemoteInteractive. You should filter out types except Interactive. Best Wishes, -David Delaune
Finally figured it how it has to be done : Posting my anwer here : #include <windows.h> #include <stdio.h> // The following constant may be defined by including NtStatus.h. #define STATUS_SUCCESS ((NTSTATUS)0x00000000L) // The LSA authentication functions are available in Unicode only. #define UNICODE int _cdecl main() { PLUID sessions; ULONG count; NTSTATUS retval; int i; retval = LsaEnumerateLogonSessions(&count, &sessions); if (retval != STATUS_SUCCESS) { wprintf (L"LsaEnumerate failed %lu\n", LsaNtStatusToWinError(retval)); return 1; } wprintf (L"Enumerate sessions received %lu sessions.\n", count); // Process the array of session LUIDs... for (i =0;i < (int) count; i++) { GetSessionData (&sessions[i]); } // Free the array of session LUIDs allocated by the LSA. LsaFreeReturnBuffer(sessions); return 0; } it works ffine...SOme body please mark this answer and close the threda as I cant :) Kushagra