Checking if app is running under a Admin account in XP
C#
2
Posts
2
Posters
0
Views
1
Watching
-
-
The application I am writing, the user has to right click on the file and tell the file to Run As and login with a admin account. Is there a way to tell if the user that is logged in running the program is a admin or not? This is in XP not vista.
Hi, this is a snippet I once used, it shows "User" or "User, Administrator" IIRC:
List roles=new List(); try { // on LP9300 this code produces an exception "Unable to get role for this RID" Thread.GetDomain().SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal); WindowsPrincipal wp=new WindowsPrincipal(WindowsIdentity.GetCurrent()); foreach(object roleName in Enum.GetValues(typeof(WindowsBuiltInRole))) if (wp.IsInRole((WindowsBuiltInRole)roleName)) roles.Add(roleName.ToString()); } catch (Exception exc) { log(exc); } log("Windows role = "+string.Join(", ", roles.ToArray()));
:)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.