Detect if user is logged in

  • Thread starter Thread starter Jarod_24
  • Start date Start date
J

Jarod_24

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/d...y/en-us/secauthn/security/winlogon_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/2004/01/04/47388.aspx but that dosent
work.
 
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
 
How do a windows-service detect whether a user is logged or not on a computer?

Why do you need to know that?


Mattias
 
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.
 
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/d...ry/en-us/wmisdk/wmi/win32_operatingsystem.asp

Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top