0

I have some code causing me trouble, it's worked until now and I can't think of anything I've changed that will have affected it (including Windows settings and code).

The code is as follows:

My.Computer.Registry.LocalMachine.CreateSubKey("SOFTWARE\EastSoft\Checkout2017")
My.Computer.Registry.LocalMachine.SetValue("SOFTWARE\EastSoft\Checkout2017", "AcceptedEULA", "True")

As I said, it used to work fine, but now I am greeted with the message:

System.UnauthorizedAccessException: 'Access to the registry key 'HKEY_LOCAL_MACHINE\SOFTWARE\EastSoft\Checkout2017' is denied.'

I am using Windows 10 Pro (64 Bit) running Visual Studio 2017 Enterprise. Any help will be greatly appreciated, thanks guys!

James

James
  • 69
  • 1
  • 9
  • 2
    Is it possible that you had been running it RUNAS Administrator, and aren't now? – Jeff Zeitlin Jul 31 '17 at 19:44
  • The code needs to be running as administrator to write to HKLM\SOFTWARE. How are you running the code? If debugging, start VS2017 using "Run as administrator". – Mark Jul 31 '17 at 19:44
  • 3
    The program is not running with correct privs, try to run as administrator. – Chuck Jul 31 '17 at 19:44
  • That's worked, thank you. Any reason why this has changed on my system? – James Jul 31 '17 at 19:53
  • I don't know the reason to why it was working before but not any longer, but using my following answer you can force your app to always run with administrator privileges: [Unhandled Exception when trying to add registry key](https://stackoverflow.com/questions/43404463/unhandled-exception-when-trying-to-add-registry-key) – Visual Vincent Jul 31 '17 at 22:28

0 Answers0