Logged on desktop user?

  • Thread starter Thread starter GTi
  • Start date Start date
G

GTi

Is there any way I can find out if there is any user logged on the
desktop from a service?
 
GTi,

Yes, but you shouldn't do this. First, there might not be a logged in
user, and second, there may be multiple logged in users.

What you want to do is have your service expose a remoting endpoint, and
then have a program that runs in the client space which connects to the
service and passes/gets the appropriate information.

Hope this helps.
 
Nicholas said:
GTi,

Yes, but you shouldn't do this. First, there might not be a logged in
user, and second, there may be multiple logged in users.

What you want to do is have your service expose a remoting endpoint, and
then have a program that runs in the client space which connects to the
service and passes/gets the appropriate information.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

GTi said:
Is there any way I can find out if there is any user logged on the
desktop from a service?

Nicholas,
Yeah - after walking round the blocks a while I ended with the same
conclusion.
Since my NT Service application is almost always depended on other
programs that only can run on the users desktop, I will change my
program to do the same as a icon by the clock.
(Note to me self: how do I do that?)
 
GTi said:
Yeah - after walking round the blocks a while I ended with the same
conclusion.
Since my NT Service application is almost always depended on other
programs that only can run on the users desktop, I will change my
program to do the same as a icon by the clock.
(Note to me self: how do I do that?)

If you do a google search for "system tray C#" you'll find lots of
hits, including
http://www.developer.com/net/csharp/article.php/3336751

Jon
 
GTi said:
Is there any way I can find out if there is any user logged on the
desktop from a service?

Yep, using System.Management classes.

...

ManagementScope msc = new ManagementScope("root\\cimv2");
// get the number of interactive logons (logontype = 2)
string queryString = "select LogonId from win32_logonsession where
logontype = 2";
using(ManagementObjectSearcher query = new ManagementObjectSearcher(msc,
new SelectQuery(queryString)))
{
if (query.Get().Count == 0) // 0 = no interactive user logon
...
else
...
}

Willy.
 
Back
Top