471,306 Members | 1,233 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,306 software developers and data experts.

Logged on desktop user?

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

Jan 4 '06 #1
4 1993
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]
- mv*@spam.guard.caspershouse.com

"GTi" <tu****@gmail.com> wrote in message
news:11********************@g44g2000cwa.googlegrou ps.com...
Is there any way I can find out if there is any user logged on the
desktop from a service?

Jan 4 '06 #2
GTi

Nicholas Paldino [.NET/C# MVP] wrote:
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]
- mv*@spam.guard.caspershouse.com

"GTi" <tu****@gmail.com> wrote in message
news:11********************@g44g2000cwa.googlegrou ps.com...
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?)

Jan 4 '06 #3
GTi wrote:
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

Jan 4 '06 #4

"GTi" <tu****@gmail.com> wrote in message
news:11********************@g44g2000cwa.googlegrou ps.com...
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.
Jan 4 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Philip Carnstam | last post: by
15 posts views Thread by paul814 | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.