简体   繁体   English

以编程方式禁用Taskmanager(ctrl + alt + del)

[英]Programmatically disable Taskmanager (ctrl+alt+del )

I am currently developing an application to configure Win10 IoT machines more easily. 我目前正在开发一个应用程序来更轻松地配置Win10物联网机器。 Imagine an user on a maching having a custom shell and pretty much all predefined shortcuts disabled so he can only work with the production application. 想象一下,一个机器上的用户有一个自定义shell,几乎所有预定义的快捷键都被禁用,因此他只能使用生产应用程序。 In order to switch users and configure the system however, "Win+L" has to stay enabled. 但是,为了切换用户并配置系统,“Win + L”必须保持启用状态。 Now in the "Win+L" screen that comes up he will still find the option to get into Taskmanager (what is not desired). 现在,在“Win + L”屏幕中,他仍然会找到进入Taskmanager的选项(不需要的)。 What the admin can to to prevent this is use gpedit and change the ctrl+alt+del options on the machine. 管理员可以防止这种情况是使用gpedit并更改机器上的ctrl + alt + del选项。 This is exactly what I want to do. 这正是我想要做的。

Programmatically disabling Taskmanager using c# 使用c#以编程方式禁用Taskmanager

Is pretty close, but this registry entry only works for the currently logged on user which in my case is the administrator as the configuration tool needs administrative priviledges (UWF Filter etc. can be configured). 非常接近, 但此注册表项仅适用于当前登录的用户 ,在我的情况下是管理员,因为配置工具需要管理权限(可以配置UWF过滤器等)。

If I try the same in LocalMachine rather than CurrentUser, the registryentry is created as expected but it has no effect at all. 如果我在LocalMachine而不是CurrentUser中尝试相同的操作,则注册表项将按预期创建,但它根本不起作用。

Thank you in advance for you help. 提前感谢您的帮助。

I found a way to achieve what I wanted: 我找到了实现我想要的方法:

public void SetTaskManager(bool enable)
    {
      // Load settings of desired user via UserName property
      using (PowerShell PowerShellInstance = PowerShell.Create())
      {
        var command = Properties.Settings.Default.LoadRegistryOfUser;
        command = command.Replace("USERNAME", UserName);
        PowerShellInstance.AddScript(command);
        var res = PowerShellInstance.Invoke();
      }

      // Create the key and entry for the registry or delete it if
      // enable == true
      RegistryKey objRegistryKey = Registry.Users.CreateSubKey(
         UserName + @"\Software\Microsoft\Windows\CurrentVersion\Policies\System");
      if (enable && objRegistryKey.GetValue("DisableTaskMgr") != null)
        objRegistryKey.DeleteValue("DisableTaskMgr");
      else
        objRegistryKey.SetValue("DisableTaskMgr", "1", RegistryValueKind.DWord);

      objRegistryKey.Close();

      // Close the registry of the user, otherwise he cant log on
      using (PowerShell PowerShellInstance = PowerShell.Create())
      {
        var command = Properties.Settings.Default.CloseRegistryOfUser;
        command = command.Replace("USERNAME", UserName);
        PowerShellInstance.AddScript(command);
        var res = PowerShellInstance.Invoke();
      }
    }

Skripts: Skripts:

LoadRegistryOfUser: reg load HKU\\USERNAME C:\\users\\USERNAME\\NTUSER.DAT LoadRegistryOfUser:reg load HKU \\ USERNAME C:\\ users \\ USERNAME \\ NTUSER.DAT

CloseRegistryOfUser: reg unload HKU\\USERNAME CloseRegistryOfUser:reg卸载HKU \\ USERNAME

Its a bit hacky but the only way I found so far. 它有点hacky但是我到目前为止找到的唯一方法。 Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM