【问题标题】:Installscript : How to close explorer windows without restart of explorer.exe process?Installscript:如何在不重新启动 explorer.exe 进程的情况下关闭资源管理器窗口?
【发布时间】:2013-07-19 11:53:24
【问题描述】:

是否可以在不重新启动 explorer.exe 进程的情况下关闭所有资源管理器窗口?

上下文:- 在卸载基于 installshield 的安装程序期间,我不得不删除一个 dll,该 dll 用于显示文件的右键单击上下文菜单。在卸载期间,我不得不删除 dll。不幸的是,它被 explorer.exe 锁定了。

是否在不重启 explorer.exe 进程的情况下关闭资源管理器窗口?

【问题讨论】:

    标签: windows installshield explorer installscript


    【解决方案1】:

    我确定您可以调用 FindWindow 并使用 SendMessage 关闭资源管理器窗口,但 explorer.exe 进程仍将运行,并且您仍将拥有文件锁定。

    Windows Installer 可以在重新启动时删除锁定的文件。如果您不想重新启动,则必须杀死并重新启动资源管理器。

    我知道这里没有其他模式。

    FindWindow Example

    WM_SYSCOMMAND message

    【讨论】:

    • 太酷了。我能够在关闭所有资源管理器窗口后手动删除 dll 文件,而无需重新启动 explorer.exe。我想我可以尝试在 installscript 中关闭资源管理器窗口。如果您可以抛出一些安装脚本来找到所有资源管理器窗口并关闭它们,那对我真的很有帮助。
    • 我不会为人们“扔安装脚本”。答案更新给你一些指示。希望它有效...
    • 感谢您更新评论。该示例查找 NOTEPAD 窗口。我的目标是找到资源管理器窗口。我试过这个来找到资源管理器窗口的句柄,不幸的是它没有返回句柄。 FindWindow("ExploreWClass","");我提供的类名用于资源管理器窗口。知道出了什么问题吗?
    • 有一个名为 Spy++ 的程序随 Visual Studio 和 Microsoft SDK 的各种版本一起提供。它会显示所有窗口句柄的列表以及它们的类名和标题。
    【解决方案2】:

    在谷歌上搜索了很多很多线索之后,我可以想出以下 c++ 程序,它只关闭资源管理器窗口而无需重新启动 explorer.exe 进程。

    这里我使用 EnumWindows 并遍历所有窗口并根据窗口的类名仅关闭资源管理器窗口。

    #include "stdafx.h"
    #include <iostream>
    #include <fstream>
    using  namespace std;
    
    wofstream myfile;
    
    BOOL CALLBACK enumWindowsProc(
      __in  HWND hWnd,
      __in  LPARAM lParam
    ) {
    
    
      int length = 255;
    
      TCHAR* buffer,*buffer1;
      buffer = new TCHAR[ length + 1 ];
      buffer1 = new TCHAR[ length + 1 ];
      memset( buffer, 0, ( length + 1 ) * sizeof( TCHAR ) );
      memset( buffer1, 0, ( length + 1 ) * sizeof( TCHAR ) );
    
      DWORD pid;
      DWORD dwThreadID = ::GetWindowThreadProcessId( hWnd, &pid);
    
      ::GetWindowText(hWnd,buffer,length +1);
      wstring windowTitle = wstring( buffer );
      delete[] buffer;
    
      //cout << windowTitle.c_str();
      ::GetClassName(hWnd,buffer1,length +1);
      wstring windowClass = wstring( buffer1 );
      delete[] buffer1;
    
      if(windowClass.compare(L"CabinetWClass") == 0 || windowClass.compare(L"ExploreWClass") == 0)
      {
          //::PostMessage(hWnd, WM_ENDSESSION, MAKEWORD(true,1), ENDSESSION_CLOSEAPP);
          //::PostMessage(hWnd, 0x5B4, 0, 0);
          PostMessage(hWnd,WM_CLOSE,0,0);
      }
    
      myfile << windowTitle.c_str();
      myfile << L"|" ;
      myfile << pid ;
      myfile << L"|" ;
      myfile << windowClass.c_str() ;
      myfile << L"\n" ;
    
      return TRUE;
    }
    
    int APIENTRY _tWinMain(HINSTANCE hInstance,
                           HINSTANCE hPrevInstance,
                           LPTSTR    lpCmdLine,
                           int       nCmdShow)
    {
        myfile.open ("processes.txt");
        BOOL enumeratingWindowsSucceeded = ::EnumWindows( enumWindowsProc, NULL );
        cin.get();
        myfile.close();
        return 0;
    }
    

    【讨论】:

      猜你喜欢
      • 2012-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多