以编程方式更改 Windows Shell [英] Programmatically change the Windows Shell

查看:51
本文介绍了以编程方式更改 Windows Shell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个将嵌入"到 Windows 7 系统中的项目,这将通过禁用任务管理器并将 Windows 外壳更改为应用程序以及其他内容来实现.

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.

我在这里要做的是以编程方式更改应用程序和 explorer.exe 之间的 Windows shell,我想知道是否有任何方法可以在 C# 中执行此操作.

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

目前我有几行代码试图更改 Windows Shell 的注册表项,但在刷新注册表编辑器后似乎没有任何反应,代码如下所示:

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();

我尝试重新启动 Windows 以查看是否允许 shell 更改完成,但无济于事.

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.

非常感谢,

理查德

推荐答案

在网上搜索了很多其他位置后,我终于让 Shell 更改为正在构建的应用程序的可执行文件.

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.

嵌入"过程是一个三步过程,对于我正在开发的软件,我们首先禁用任务管理器,然后在本地机器注册表中设置 shell 可执行文件,然后在当前用户注册表.

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);
    }
}

在此示例中,变量shell"是一个字符串,其中包含用作新 Windows Shell 的可执行文件的路径.

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

除此之外,还有一种取消嵌入"软件的方法,该方法只是从当前用户注册表中删除DisableTaskMgr"和Shell"值,还会重置本地计算机注册表中的Shell"值到explorer.exe".

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

我希望这可以帮助那些在以编程方式更改 Windows Shell 时遇到问题的其他人.

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

问候,

理查德

这篇关于以编程方式更改 Windows Shell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆