When I use the following code My.Computer.Registry.LocalMachine.OpenSubKey(\"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\", True).SetValue(Application.ProductName, App
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:
Right-click your project in Visual Studio's Solution Explorer window and press Properties.
Make sure you are on the Application tab, then press the button that says View Windows Settings.
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" />