Unhandled Exception when trying to add registry key

前端 未结 1 593
死守一世寂寞
死守一世寂寞 2021-01-27 10:26

When I use the following code My.Computer.Registry.LocalMachine.OpenSubKey(\"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\", True).SetValue(Application.ProductName, App

相关标签:
1条回答
  • 2021-01-27 11:27

    You get "Access denied" because you are required to run your app with administrative privileges if you want to write to the HKEY_LOCAL_MACHINE key.

    You can force your app to only run with, and therefore always ask for, admin privileges by doing the following steps:

    1. Right-click your project in Visual Studio's Solution Explorer window and press Properties.

    2. Make sure you are on the Application tab, then press the button that says View Windows Settings.

    3. In the app.manifest file that opens in the editor locate the following:

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

      and replace it with:

      <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
      
    0 讨论(0)
提交回复
热议问题