Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

How to detect current user of windows

Question posted by: vijayB (Member) on July 3rd, 2008 02:04 PM
Hello friends,

I want to detect the current user which is logged on to windows system using vb.net.
This is required to notify end user under what privilages application is running.

Please help
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
insertAlias's Avatar
insertAlias
Moderator
942 Posts
July 3rd, 2008
02:18 PM
#2

Re: How to detect current user of windows
Environment.UserName

Reply
cloud255's Avatar
cloud255
Member
104 Posts
July 3rd, 2008
02:39 PM
#3

Re: How to detect current user of windows
One day ...

people started consulting text books before posting questions
and magically the forum only consisted of questions that actually require
experience and logic to solve ...

one day ...

Reply
insertAlias's Avatar
insertAlias
Moderator
942 Posts
July 3rd, 2008
02:52 PM
#4

Re: How to detect current user of windows
Quote:
Originally Posted by cloud255
One day ...

people started consulting text books before posting questions
and magically the forum only consisted of questions that actually require
experience and logic to solve ...

one day ...


You said it, bro. The only reason I bothered answering this one is because I knew it off the top of my head and it literally took two words.

Reply
vijayB's Avatar
vijayB
Member
40 Posts
July 4th, 2008
08:03 AM
#5

Re: How to detect current user of windows
Quote:
Originally Posted by cloud255
One day ...

people started consulting text books before posting questions
and magically the forum only consisted of questions that actually require
experience and logic to solve ...

one day ...


Thanks for the help friendzzzzz
But this is not the solution I was looking for. I know we can get current user name using Environment.
What I was looking for is, current user, i.e., whether the current user is having administrator privilages or it is a restricted account.

Anyways, I have found the solution for this, yesterday itself.
Thanks once again for your valuable help.

Reply
alag20's Avatar
alag20
Member
61 Posts
July 4th, 2008
08:08 AM
#6

Re: How to detect current user of windows
Quote:
Originally Posted by vijayB
Thanks for the help friendzzzzz
But this is not the solution I was looking for. I know we can get current user name using Environment.
What I was looking for is, current user, i.e., whether the current user is having administrator privilages or it is a restricted account.

Anyways, I have found the solution for this, yesterday itself.
Thanks once again for your valuable help.

We are happy that you found your solution. Though your question seemed as if you wanted to get their name rather than their rights!

Reply
vijayB's Avatar
vijayB
Member
40 Posts
July 4th, 2008
08:15 AM
#7

Re: How to detect current user of windows
Quote:
Originally Posted by alag20
We are happy that you found your solution. Though your question seemed as if you wanted to get their name rather than their rights!



Ya, I m really sorry. Next time I will be more specific.
Thanks.

Reply
insertAlias's Avatar
insertAlias
Moderator
942 Posts
July 4th, 2008
09:34 PM
#8

Re: How to detect current user of windows
If you don't mind, post your solution. That way, anyone else searching for the same kind of help will be able to get the help they need as well.

Thanks.

Reply
vijayB's Avatar
vijayB
Member
40 Posts
July 7th, 2008
03:26 PM
#9

Re: How to detect current user of windows
Quote:
Originally Posted by insertAlias
If you don't mind, post your solution. That way, anyone else searching for the same kind of help will be able to get the help they need as well.

Thanks.



Ya sure, it will be my pleasure.
Here is the solution;

Function IsAdministrator() As Boolean

System.AppDomain.CurrentDomain.SetPrincipalPolicyS ystem.Security.Principal.PrincipalPolicy.WindowsPr incipal)
Dim WP As System.Security.Principal.WindowsPrincipal
WP = System.Threading.Thread.CurrentPrincipal
Return WP.IsInRole(System.Security.Principal.WindowsBuilt InRole.Administrator)

End Function

One just needs to call this function, to get current role of administrator.

Reply
insertAlias's Avatar
insertAlias
Moderator
942 Posts
July 7th, 2008
03:31 PM
#10

Re: How to detect current user of windows
Thanks for posting it.

Reply
Daxthecon's Avatar
Daxthecon
Member
37 Posts
July 7th, 2008
05:28 PM
#11

Re: How to detect current user of windows
I know what you thought the original question was is easy and in a book but I honestly forgot it and I don't have the book on me. Could anyone reference a google search real quick to help me find the answer to the original question(a list of those codes to gather the information that the windows authentication stores and transfers). It would be greatly appreciated. I'm in such a mind fog right now. Please forgive me.

Reply
Reply
Not the answer you were looking for? Post your question . . .
180,804 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Top .NET Forum Contributors