Click here to Skip to main content
14,643,383 members
Rate this:
Please Sign up or sign in to vote.
See more:
i m having to create an applicaation that has to run as admin. now i know i can have the user right click and run as admin but i need a safety if they open it as their regular user account.

the catch with this is work wants to use the clickonce function which i know that it dosent support admin rights.

is there any what that on form load if it dosent find an admin account it prompts you with uac to enter in your admin credentials? please help i have been searching the web and not a lot of information out there on this issue.
Rate this:
Please Sign up or sign in to vote.

Solution 1

Yes you can perform this by adding a manifest file for your application and embed it to your application while compilation. You can perform following steps for doing this.

1. Create a file having name "<<application name>>.exe.manifest" in the same folder where project file is present.
2. Write below provided lines in it
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"

xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2"

  <assemblyIdentity version="" name="ApplicationName"/>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

3. Make sure that in place of Application name, provide your executable name in above XML.

4. Now go to "Project Properties->Configuration Property->Linker->Manifest File".
5. Change "UAC Execution Level" to "requireAdministrator".
6. After this go to "Project Properties->Configuration Property->Manifest Tool->Input and Output".
7. Add yo9ur manifest name in "Additional Manifest Files" text box.
8. Now compile the application and generate executable.
9 Now when you will run this application, it will require admin privileges.

Please find more details for creating and embedding a manifest file at link[^]
Zachary.shupp 29-Feb-12 10:01am
I like this method and i will try it out but will this work with using the click once install method?
Zachary.shupp 29-Feb-12 11:06am
i can not find step 4. i can get to the main manifest under properties>application>view windows settings. I m using visual studio 2010 ultimate if that makes a different.
Chandrakantt 29-Feb-12 11:41am
Linker->Manifest file, I have uploaded a image you can look at link
Zachary.shupp 29-Feb-12 13:13pm
i see where the issue is and its were using different versions. In 2010 we dont have that layout.
Chandrakantt 1-Mar-12 0:43am
Yes you are correct, layout of property dialogs have changed in VS 2010. So in 2010 you have to add your custom manifest file and then it will be shown in the dropdown box. from there you can select the manifest file.
It at the image I have uploaded
Rate this:
Please Sign up or sign in to vote.

Solution 2

What I have done is created my own updater when the application opens. Then I created an installer with visual studio that when a new update installs It will remove the old version and install the new one. This makes it so I can have full admin rights.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100