C# - 禁用任务管理器错误
本文关键字:任务管理器 错误 | 更新日期: 2023-09-27 18:32:16
代码如下:
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());
}
}
但是我收到以下错误。
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
你如何解决它?
尝试在管理员模式下运行此应用程序