-4

I need to run my .exe with admin privileged. I searched google and found piece of xml which I need to put in app.config file. here is the xml:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="My Application" type="win32"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
  <requestedPrivileges>
    <requestedExecutionLevel level="requireAdministrator"/>
  </requestedPrivileges>
</security>

IS this enough to run any exe with admin privilegeS?. thanks.

jAC
  • 5,195
  • 6
  • 40
  • 55
Thomas
  • 33,544
  • 126
  • 357
  • 626
  • Hard to decode what you are asking. If you mean "does any process I start from this one run elevated as well?" then the answer is Yes. – Hans Passant Dec 14 '12 at 14:48

1 Answers1

2

Yes, but the requestedExecutionLevel element part is only the first half. If the UAC is turned off, you have to perform a check for privileges and put up a error dialog if the user is not admin. You can get the privileges with the WindowsPrincipal.IsInRole Method

To create a Run as ... dialog take a look at this: http://www.codeproject.com/Articles/7168/RunAs-Class

jAC
  • 5,195
  • 6
  • 40
  • 55