简体   繁体   中英

Programmatically disable Taskmanager (ctrl+alt+del )

I am currently developing an application to configure Win10 IoT machines more easily. 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. In order to switch users and configure the system however, "Win+L" has to stay enabled. Now in the "Win+L" screen that comes up he will still find the option to get into Taskmanager (what is not desired). What the admin can to to prevent this is use gpedit and change the ctrl+alt+del options on the machine. This is exactly what I want to do.

Programmatically disabling Taskmanager using c#

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).

If I try the same in LocalMachine rather than CurrentUser, the registryentry is created as expected but it has no effect at all.

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:

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

CloseRegistryOfUser: reg unload HKU\\USERNAME

Its a bit hacky but the only way I found so far. Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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