Vista + VB.NET - Access Denied while writing to HKEY_LOCAL_MACHINE

前端 未结 3 1191
挽巷
挽巷 2021-01-23 21:39

I want my program to be able to edit a values within a registry key that resides in \'HKEY_LOCAL_MACHINE\'

    My.Computer.Registry.SetValue(\"HKEY_LOCAL_MACHINE         


        
3条回答
  •  灰色年华
    2021-01-23 21:59

    You are running into Vista's UAC feature. It will not let you write to arbitrary places in the HKLM hive because you are not running with Administrative priviledges.

    There are two ways to work around this issue

    1. Run the program with Administrative priviledges (different than running a program as an account which has Administrative priviledges)
    2. Choose another place, perhaps HKCU, to store the data

    The second option is much better as it allows your application to run with non-Admin priviledges which you can't always assume your user has.

    Here is a fairly detailed article on UAC. It's not 100% programming material but it gives a good explanation as to what exactly it is and you can hopefully relate that to your particular program: http://technet.microsoft.com/en-us/library/cc709691.aspx

提交回复
热议问题