3

Possible Duplicate:
Disabling UAC programmatically

How can I change never notify in 'user account control settings' by c#? by manual : User Accounts -> user account control settings -> change by scall bar to 'never notify'.

(I need it for automated integration tests )

Community
  • 1
  • 1
sari k
  • 2,051
  • 6
  • 28
  • 34
  • @HasanKhan: you will only be able to change it when you are executing as an Administrator. They are all powerful anyway and should know what they are doing. – Emond Oct 03 '11 at 09:49
  • After all, with years of running as administrator in previous Windows versions, users have clearly demonstrated their grasp of "what they are doing", and as a consequence, Windows has a really good reputation as a secure OS. @sari k : please ensure that you prompt the user VERY clearly about the changes you want to make and allow whatever it is you are writing to function correctly w/o requiring UAC to be disabled. – spender Oct 03 '11 at 09:52

2 Answers2

6

As an Administrator you could change the appropriate registry key using C#:

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System

Have a look at this answer: https://superuser.com/questions/83677/disabling-uac-on-windows-7/83678#83678

Community
  • 1
  • 1
Emond
  • 50,210
  • 11
  • 84
  • 115
3

This should do the trick.

using Microsoft.Win32;

RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System");
key.SetValue("EnableLUA", "0");
key.Close();
Bali C
  • 30,582
  • 35
  • 123
  • 152