locked
How to elevate c# application to update registry? RRS feed

  • Question

  • Hi,

    How do I elevate my application to update registry in windows 7 or in vista?
    Wednesday, November 11, 2009 3:57 PM

Answers

  • Hi,

    You can always run your c# application under administrator previllige, to do this add a Application manifest file into your project and change the setting as follow:

    <?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" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
      <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
        <security>
          <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
            <!-- UAC Manifest Options
                If you want to change the Windows User Account Control level replace the
                requestedExecutionLevel node with one of the following.

            <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
            <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
            <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />

                If you want to utilize File and Registry Virtualization for backward
                compatibility then delete the requestedExecutionLevel node.
            -->
           <requestedExecutionLevel  level="requireAdministrator" uiAccess="true" />
          </requestedPrivileges>
        </security>
      </trustInfo>
    </asmv1:assembly>

    Thanks
    Binze


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Bin-ze Zhao Tuesday, November 17, 2009 3:22 AM
    Monday, November 16, 2009 10:44 AM
  • You'll need to use the .NET Framework 2.0 Configuration tool. Click the Runtime Security Policy node, and then click Increase Assembly Trust. You can also click the Evaluate Assembly to see what security policy your assembly is currently using.
    • Marked as answer by Bin-ze Zhao Tuesday, November 17, 2009 3:22 AM
    Wednesday, November 11, 2009 4:35 PM

All replies

  • You'll need to use the .NET Framework 2.0 Configuration tool. Click the Runtime Security Policy node, and then click Increase Assembly Trust. You can also click the Evaluate Assembly to see what security policy your assembly is currently using.
    • Marked as answer by Bin-ze Zhao Tuesday, November 17, 2009 3:22 AM
    Wednesday, November 11, 2009 4:35 PM
  • Hi,

    You can always run your c# application under administrator previllige, to do this add a Application manifest file into your project and change the setting as follow:

    <?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" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
      <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
        <security>
          <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
            <!-- UAC Manifest Options
                If you want to change the Windows User Account Control level replace the
                requestedExecutionLevel node with one of the following.

            <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
            <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
            <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />

                If you want to utilize File and Registry Virtualization for backward
                compatibility then delete the requestedExecutionLevel node.
            -->
           <requestedExecutionLevel  level="requireAdministrator" uiAccess="true" />
          </requestedPrivileges>
        </security>
      </trustInfo>
    </asmv1:assembly>

    Thanks
    Binze


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Bin-ze Zhao Tuesday, November 17, 2009 3:22 AM
    Monday, November 16, 2009 10:44 AM