开发者

Programmatically change the Windows Shell

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 t开发者_运维技巧he 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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜