[英]Installscript : How to close explorer windows without restart of explorer.exe process?
反正有没有关闭所有资源管理器窗口而无需重新启动explorer.exe进程?
上下文:-在卸载基于installshield的安装程序期间,我必须删除一个dll,该dll用于显示文件的右键单击上下文菜单。 在卸载过程中,我必须删除dll。 不幸的是,它已被explorer.exe锁定。
反正有没有关闭资源管理器窗口而没有重新启动explorer.exe进程吗?
我确定您可以调用FindWindow并使用SendMessage关闭资源管理器窗口,但explorer.exe进程仍将运行,并且您将仍然具有文件锁定。
Windows Installer可以在重新启动时删除锁定的文件。 如果您不想重新启动,则必须终止并重新启动资源管理器。
我在这里没有其他模式。
经过大量的搜索之后,我可以想出以下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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.