15

I'm working on a project that will be "embedded" into a Windows 7 system, this is going to be achieved by disabling task manager and changing the windows shell to the application, as well as other things.

What I'm looking to do here is programmatically change the Windows shell between the application and explorer.exe, I would like to know if there's any way to do this in C#.

Currently I have a few lines of code that attempt to change the registry entry for the Windows Shell, but nothing appears to happen after refreshing the Registry Editor, the code looks like this:

    regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE", true).OpenSubKey("Microsoft", true).OpenSubKey("Windows NT", true).OpenSubKey("CurrentVersion", true).OpenSubKey("Winlogon", true);
    regKey.DeleteValue("Shell");
    regKey.SetValue("Shell", shell);
    regKey.Close();

I've tried restarting windows to see if that allows the shell change to complete, but to no avail.

I'd greatly appreciate it if someone can tell me if it's even possible to do it programmatically, and where I'm going wrong with it.

Also, I'd be grateful to know if there's a way to code the program so that it's always running with admin privileges so that registry editing will work.

Many Thanks,

Richard

5
  • 1
    Who in the right mind would install an application that disables the task manager? Oct 11, 2011 at 15:40
  • 1
    @Ramhound this question was not about disabling task manager - the application is not going to be sold to the general public, because the general public would have no use for it, this is for a specialist application where sensitive data, and the application itself needs to be protected from theft/tamper Oct 11, 2011 at 15:51
  • @RichardBenn: I think you should ask about that then. Usually to protect against sensitive data / theft, we use passwords and encryption. Why have you ignored these standard paths? No security expert would suggest that you increase security by changing the windows shell.
    – tenfour
    Oct 12, 2011 at 15:55
  • @tenfour Why do you assume that Passwords and encryption haven't already been employed? The data in the files is encrypted, but it's required that there's more protection over the data than that. The replacement of the shell is to stop people from using windows explorer to make a copy of the executable and attempt to reverse engineer it, hence also the reason for disabling Task Manager. Oct 13, 2011 at 10:53
  • 1
    Because I can't imagine what your solutions could add in the way of "data protection" on top of encryption. It sounds like you want to basically implement a kiosk mode where no other applications are running (not just TM & Explorer). Otherwise wouldn't users just open a command prompt to copy the file? Or more likely: email it to themselves? There are definitely existing kiosk solutions to this end.
    – tenfour
    Oct 13, 2011 at 11:15

1 Answer 1

15

After much searching of other locations on the net, I have finally got the Shell to change to the executable file of the application that is being built.

The "Embedding" process is a three step process, in the case of the software I'm working on, we start by disabling Task Manager, We then set the shell executable in the Local Machine registry and then repeat the process in the Current User registry.

Below is the code that achieves this:

public void embedSoftware()
{
    try
    {
        // Disable Task Manager
        regKey = Registry.CurrentUser.OpenSubKey(subKey, true).CreateSubKey("System");
        regKey.SetValue("DisableTaskMgr", 1);
        regKey.Close();
        // Change the Local Machine shell executable
        regKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", true);
        regKey.SetValue("Shell", shell, RegistryValueKind.String);
        regKey.Close();
        // Create the Shell executable Registry entry for Current User
        regKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\Winlogon", true);
        regKey.SetValue("Shell", shell);
        regKey.Close();
        MessageBox.Show("Embedding Complete");

    }
    catch (Exception e)
    {
        MessageBox.Show(e.Message);
    }
}

In this example the variable "shell" is a string containing the path of the executable to use as the new Windows Shell.

Further to this there's a method to "un-embed" the software, this method simply deletes the "DisableTaskMgr" and "Shell" values from the Current User registries, it also resets the "Shell" value in the Local Machine registry to "explorer.exe".

I hope this helps others out there who're having trouble changing Windows Shells programmatically.

Regards,

Richard

1
  • 2
    Sorry, I'm still quite new to posting questions and answers here. I edited the answer to be an answer only Oct 12, 2011 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.