Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用c关闭个性化窗口#_C#_Windows_Personalization - Fatal编程技术网

C# 使用c关闭个性化窗口#

C# 使用c关闭个性化窗口#,c#,windows,personalization,C#,Windows,Personalization,我已经编写了一个程序来更改windows主题,但是在更改主题后,个性化窗口仍然打开,我想关闭它。我试着用熟悉的进程名使用process.kill(),但没有成功。多谢各位 我正在做的工作的代码如下: ProcessStartInfo theinfo = new ProcessStartInfo(themepath + "aero.theme"); theinfo.CreateNoWindow = true; Process thepr = new Process(); thepr.StartIn

我已经编写了一个程序来更改windows主题,但是在更改主题后,个性化窗口仍然打开,我想关闭它。我试着用熟悉的进程名使用process.kill(),但没有成功。多谢各位

我正在做的工作的代码如下:

ProcessStartInfo theinfo = new ProcessStartInfo(themepath + "aero.theme");
theinfo.CreateNoWindow = true;
Process thepr = new Process();
thepr.StartInfo = theinfo;
thepr.Start();
其中“themepath”是指向aero.theme的字符串位置。 我甚至将CreateNoWindow启用为true,然后它会打开个性化设置以更改主题,但不会自动关闭它。

您需要通过窗口句柄的名称获取窗口句柄,然后向其发送关闭消息。这可以防止必须终止任何进程。有关获取窗口的信息,请参阅。有关从控制柄关闭窗口的信息,请参见


在看到代码并进行一些挖掘之后,您可以通过两次注册表编辑来完成这项工作。您应该阅读本文,让您的程序编辑有问题的两个注册表项。

首先使用find window,通过使用FindWindow从它们的名称中获取窗口

 [DllImport("user32.dll")]
    public static extern int FindWindow(string lpClassName,string lpWindowName);
它将返回所需窗口的句柄。现在,您可以使用“发送消息”将其关闭

 [DllImport("User32.dll")]
    public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);
    public const int WM_SYSCOMMAND = 0x0112;
    public const int SC_CLOSE = 0xF060;
        private void closeWindow()
         {
          // retrieve the handler of the window  
            int iHandle = FindWindow("CabinetWClass", "Personalization");
            if (iHandle > 0)
             {
                 SendMessage(iHandle, WM_SYSCOMMAND, SC_CLOSE, 0);  
             }  
          }   

我试过这个,但也不起作用。我对你提供的关于从手柄关闭窗口的第二篇文章链接也有点困惑。顺便说一句,谢谢你的帮助。现在我看到你的代码,我看到你没有窗口关闭。由于您是从文件关联启动的,而不是特定的可执行文件,因此您的进程可能是explorer.exe,Windows会保护您不被杀死。您可能应该通过注册表更改主题,而不是尝试自动化Windows资源管理器。