I need to restrict access to my application to only one specific user account. I have found classes under WMI to find users accounts, but I don´t know how to recognize which one is running my app.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are simpler ways to get the current username than using WMI.
WindowsIdentity.GetCurrent().Name will get you the name of the current Windows user.
Environment.Username will get you the name of the currently logged on user.
The difference between these two is that
WindowsIdentity.GetCurrent().Namewill also include the domain name as well as the username (ie.MYDOMAIN\adrianinstead ofadrian). If you need the domain name fromEnvironment, you can use Environment.UserDomainName.EDIT
If you really want to do it using WMI, you can do this:
Unfortunately, there is no indexer property on
ManagementObjectCollectionso you have to enumerate it to get the first (and only) result.