以编程方式更改 Windows Shell

发布于 2024-12-09 06:34:35 字数 727 浏览 1 评论 0原文

我正在开发一个将“嵌入”到 Windows 7 系统中的项目,这将通过禁用任务管理器并将 Windows shell 更改为应用程序以及其他操作来实现。

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

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

    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'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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南渊 2024-12-16 06:34:35

经过在网络上的其他位置进行大量搜索后,我终于将 Shell 更改为正在构建的应用程序的可执行文件。

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

下面是实现此目的的代码:

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 的可执行文件的路径。

除此之外,还有一种“取消嵌入”软件的方法,该方法只是从当前用户注册表中删除“DisableTaskMgr”和“Shell”值,还将本地计算机注册表中的“Shell”值重置为“explorer” 。EXE文件”。

我希望这可以帮助其他在以编程方式更改 Windows 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.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文