Search code examples
vb.netwindowsregistryuac

Why can not write registry from application what started automatically from HKLM\Software\Microsoft\Windows\CurrentVersion\Run


My VB.NET program automatically start from registry

HKLM\Software\Microsoft\Windows\CurrentVersion\Run

But when it try to write a registry key this error occured:

System.UnauthorizedAccessException: Access to the registry key HKEY_LOCAL_MACHINE\SOFTWARE\MyCorporation\MyApplication is denied.


Solution

  • Because writing to HKLM requires, in general, admin access, and your app runs as a non-privileged user. Modify your app to use HKCU instead. Alternatively you can add a manifest to require elevated privileges.

    You should consider creating a service instead of an application that runs on start.