C# - 禁用任务管理器错误

时间:2014-11-28 08:41:41

标签: c# .net registry taskmanager

代码如下:

    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

你如何解决?

1 个答案:

答案 0 :(得分:0)

尝试在管理员模式下运行此应用程序