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

Testing that my application is being run as administrator

P: n/a
Hi,
I'm a complete beginner regarding authentication/permissions etc and have no
idea what/where to start implementing whatever I need in my C# applications.
I've been trying to find info on the web but I seem to be hopeless at
knowing the correct terminology to get any sort of positive search result.
I've just written a utility application that needs to run a series of third
party installation packages, writes to their inifiles after
installation,start/stop services, reads/writes files, registry etc etc.
Expected to be run on Win 2000, XP and Vista.
My solution was to do a check on application startup that it was being run
as administrator, no idea where to start in doing that, and no idea if
that's needed in Win2000 or XP anyway.
Can anyone help me please? Especially with pointers towards links to noob
aimed articles but some code samples for testing for administrator so i can
at least show the user a warning.
thanks :)

Jun 30 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Jun 30, 6:31*am, "Claire" <h...@notonyournelly.coomwrote:
Hi,
I'm a complete beginner regarding authentication/permissions etc and have no
idea what/where to start implementing whatever I need in my C# applications.
I've been trying to find info on the web but I seem to be hopeless at
knowing the correct terminology to get any sort of positive search result.
I've just written a utility application that needs to run a series of third
party installation packages, writes to their inifiles after
installation,start/stop services, reads/writes files, registry etc etc.
Expected to be run on Win 2000, XP and Vista.
My solution was to do a check on application startup that it was being run
as administrator, no idea where to start in doing that, and no idea if
that's needed in Win2000 or XP anyway.
Can anyone help me please? Especially with pointers towards links to noob
aimed articles but some code samples for testing for administrator so i can
at least show the user a warning.
thanks :)
You should check if your current Principal is member of the admin
group:
Take a look at WindowsPrincipal.IsInRole method, you will get all you
need there
Jun 30 '08 #2

P: n/a
>>You should check if your current Principal is member of the admin
group:
Take a look at WindowsPrincipal.IsInRole method, you will get all you
need there
thanks ignacio :)
WindowsIdentity windowsIdentity = WindowsIdentity.GetCurrent();

WindowsPrincipal pr = new WindowsPrincipal(windowsIdentity);

if (!pr.IsInRole(WindowsBuiltInRole.Administrator))

MessageBox.Show(gui.frmProcess_WrongPrivileges);


Jul 2 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.