问题
The code is as follows:
public void KillCtrlAltDelete()
{
RegistryKey regkey;
string keyValueInt = "1";
string subKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System";
try
{
regkey = Registry.CurrentUser.CreateSubKey(subKey);
regkey.SetValue("DisableTaskMgr", keyValueInt);
regkey.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
But I was getting the following error.
System.UnauthorizedAccessException:Access to the registry key'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System' is denied.
at Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String str)
at Microsoft.Win32.RegistryKey.CreateSubKey(String subkey, RegistryKeyPermissionCheck permissionCheck, RegistrySecurity registrySecurity)
at BlockTask.Form1.KillCtrlAltDelete() in C:\Users\ASUS\Documents\Visual Studio 2008\Projects\BlockTask\BlockTask\Form1.cs:line 28
How do you fix it?
回答1:
Try to Run this Application on Administrator mode
来源:https://stackoverflow.com/questions/27184781/c-sharp-disable-task-manager-error