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

user in domain

P: n/a
How to check if a user is logged into domain ?

Hrcko
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hrvoje,

I don't believe that you can do that, since there are many different
ways that a user can be logged on (a user can be logged on to two different
machines), and I don't believe that the domain controller keeps track of
this.

Are you in a controlled environment? Meaning, could you get an app
installed on every machine which will do this for you (you would have to
write a replacement for GINA as well, but I don't know that will intercept
calls to LogonUser though, which could be a problem).

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Hrvoje Voda" <hr*********@luatech.com> wrote in message
news:df**********@ss405.t-com.hr...
How to check if a user is logged into domain ?

Hrcko

Nov 17 '05 #2

P: n/a

"Hrvoje Voda" <hr*********@luatech.com> wrote in message
news:df**********@ss405.t-com.hr...
How to check if a user is logged into domain ?

Hrcko


If you want to know wheter the current user is a domain user, you can check
the environment variable USERDOMAIN.

Running XP or higher, you can use System.Management and WMI's class
win32_useraccount.

Here is a sample..

String username = new
WindowsPrincipal(WindowsIdentity.GetCurrent()).Ide ntity.Name;
username = username.Insert(username.IndexOf('\\'), @"\");
// check if current user is a non local account
string queryString = "select Domain from win32_useraccount where
localaccount=false and caption='" + username + "'" ;
using(ManagementObjectSearcher query = new ManagementObjectSearcher( new
SelectQuery(queryString)))
{
foreach( ManagementObject mo in query.Get()) {
Console.WriteLine( "Domain '{0}'", mo["Domain"].ToString());
}
}

If you are looking for the curent interactive logon user(s) things get a bit
more complicated.

Willy.
Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.