C# - Disable Task manager error

邮差的信 提交于 2019-12-08 11:21:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!