2

I want's to store sql server name to system Environment variables and get when it needed;

i tried this:

Environment.SetEnvironmentVariable("Varname","VarVal",EnvironmnetVariableTarget.Machine);

But it shows an error:

Requested Registry Access Not Allowed

Called Security Exception....

What to do?

Just code
  • 13,553
  • 10
  • 51
  • 93
  • As per the [documentation](https://msdn.microsoft.com/en-us/library/96xafkes(v=vs.110).aspx) for that method. your app does not have the required permissions for that operation. – Nasreddine May 29 '17 at 12:25
  • SO HOW CAN I PERMIT IT –  May 29 '17 at 12:28
  • @morihardev take a look at my answer **:|** – Adola May 29 '17 at 12:29
  • See the [linked question](https://stackoverflow.com/questions/2818179/how-do-i-force-my-net-application-to-run-as-administrator) by @Adola. – Nasreddine May 29 '17 at 12:29

1 Answers1

2

You're accessing HKEY_LOCAL_MACHINE. You will need to get the required access from Windows. Take a look at this post about getting the right privilege.

Adola
  • 337
  • 1
  • 16