By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,946 Members | 745 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,946 IT Pros & Developers. It's quick & easy.

Detect if user is logged in

P: n/a
How do a windows-service detect whether a user is logged or not on a computer?

So far i've found nothing in the windows api or any code examples that will allow me to figure this out.

The solution i have today is to use Diagnostics.Process.GetProcesses and then iterate through the array i get and look for
explorer.exe
Explorer.exe is not loaded when a user is logged out of a computer.

I found this on winlogon states:
http://msdn.microsoft.com/library/de...gon_states.asp
but i cant see any api methods that will return the state that winlogon is actually in...

the only solution getting close to this issue i found at http://weblogs.asp.net/ralfw/archive.../04/47388.aspx but that dosent
work.
Jan 21 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi,

Are you looking to see who the machine is logged in as or if a
user is logged into your active directory? What version of vb are you using?

Ken
---------------------

"Jarod_24" wrote:
How do a windows-service detect whether a user is logged or not on a computer?

So far i've found nothing in the windows api or any code examples that will allow me to figure this out.

The solution i have today is to use Diagnostics.Process.GetProcesses and then iterate through the array i get and look for
explorer.exe
Explorer.exe is not loaded when a user is logged out of a computer.

I found this on winlogon states:
http://msdn.microsoft.com/library/de...gon_states.asp
but i cant see any api methods that will return the state that winlogon is actually in...

the only solution getting close to this issue i found at http://weblogs.asp.net/ralfw/archive.../04/47388.aspx but that dosent
work.

Jan 21 '06 #2

P: n/a
>How do a windows-service detect whether a user is logged or not on a computer?

Why do you need to know that?
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jan 21 '06 #3

P: n/a
Im writing a power saving service that runs on a computer and i need to see if a user is logged in on the machine that the service
itself is installed on.
No active directory. Basically, if there is a user logged in, the service will for example do a Hibernate, but if there is no user
logged in, then it will to a Shutdown.

Im using VS2003.
"Ken Tucker [MVP]" <Ke**********@discussions.microsoft.com> wrote in message
news:88**********************************@microsof t.com...
Hi,

Are you looking to see who the machine is logged in as or if a
user is logged into your active directory? What version of vb are you using?

Ken
---------------------

"Jarod_24" wrote:
How do a windows-service detect whether a user is logged or not on a computer?

So far i've found nothing in the windows api or any code examples that will allow me to figure this out.

The solution i have today is to use Diagnostics.Process.GetProcesses and then iterate through the array i get and look for
explorer.exe
Explorer.exe is not loaded when a user is logged out of a computer.

I found this on winlogon states:
http://msdn.microsoft.com/library/de...gon_states.asp
but i cant see any api methods that will return the state that winlogon is actually in...

the only solution getting close to this issue i found at http://weblogs.asp.net/ralfw/archive.../04/47388.aspx but that
dosent
work.

Jan 21 '06 #4

P: n/a
Hi,

Not really sure if this will work but maybe you could use the
win32_operatingsystems numberofusers property. Add a reference to
system.management

Dim moReturn As Management.ManagementObjectCollection
Dim moSearch As Management.ManagementObjectSearcher
Dim mo As Management.ManagementObject

moSearch = New Management.ManagementObjectSearcher("Select * from
Win32_OperatingSystem")
moReturn = moSearch.Get

For Each mo In moReturn

Try
Trace.WriteLine(mo("NumberOfUsers").ToString)
Catch ex As System.Exception
Trace.WriteLine(ex.ToString)
End Try

Next
http://msdn.microsoft.com/library/de...tingsystem.asp

Ken
-----------------

"Jarod_24" <ja******@hotmail.com> wrote in message
news:43**********************@titian.nntpserver.co m...
Im writing a power saving service that runs on a computer and i need to
see if a user is logged in on the machine that the service itself is
installed on.
No active directory. Basically, if there is a user logged in, the service
will for example do a Hibernate, but if there is no user logged in, then
it will to a Shutdown.

Im using VS2003.
"Ken Tucker [MVP]" <Ke**********@discussions.microsoft.com> wrote in
message news:88**********************************@microsof t.com...
Hi,

Are you looking to see who the machine is logged in as or if a
user is logged into your active directory? What version of vb are you
using?

Ken
---------------------

"Jarod_24" wrote:
How do a windows-service detect whether a user is logged or not on a
computer?

So far i've found nothing in the windows api or any code examples that
will allow me to figure this out.

The solution i have today is to use Diagnostics.Process.GetProcesses and
then iterate through the array i get and look for
explorer.exe
Explorer.exe is not loaded when a user is logged out of a computer.

I found this on winlogon states:
http://msdn.microsoft.com/library/de...gon_states.asp
but i cant see any api methods that will return the state that winlogon
is actually in...

the only solution getting close to this issue i found at
http://weblogs.asp.net/ralfw/archive.../04/47388.aspx but that
dosent
work.


Jan 21 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.