Ei, olhe! Uma duplicação entre sites ! : D
Eu fiz e enviei um programa que tenta parar e iniciar o Explorer . Nem sempre funciona, dependendo do estado do Explorer, mas geralmente acontece. :)
Aqui está o código-fonte (curto), escrito em D :
import core.stdc.wchar_, core.sys.windows.windows;
struct STARTUPINFOW { DWORD cb; LPWSTR lpReserved, lpDesktop, lpTitle; DWORD dwX, dwY, dwXSize, dwYSize, dwXCountChars, dwYCountChars, dwFillAttribute, dwFlags; WORD wShowWindow; WORD cbReserved2; LPBYTE lpReserved2; HANDLE hStdInput, hStdOutput, hStdError; }
struct PROCESS_INFORMATION { HANDLE hProcess; HANDLE hThread; DWORD dwProcessId; DWORD dwThreadId; }
extern(C) static int D15TypeInfo_Struct6__vtblZ = 0; //Don't need this
extern(C) ubyte[1024] D4core3sys7windows7windows16WIN32_FIND_DATAW6__initZ; //Don't need this
pragma(lib, "msvcrt.lib"); pragma(startaddress, mainCRTStartup);
int mainCRTStartup() //NOT int main(), since we don't need Phobos or the D runtime
{
const HWND hWnd = FindWindowW("Shell_TrayWnd", null);
if (hWnd != null)
{
DWORD pid;
GetWindowThreadProcessId(hWnd, pid);
HANDLE hProcess = OpenProcess(0x00100000, false, pid);
wchar pathBuf[32 * 1024] = void;
auto si = STARTUPINFOW(STARTUPINFOW.sizeof);
PROCESS_INFORMATION pi;
if (hProcess != null && ExpandEnvironmentStringsW(r"%SystemRoot%\explorer.exe", pathBuf.ptr, pathBuf.length) > 0
&& SendMessageW(hWnd, 0x5B4, 0, 0) == 0 && WaitForSingleObject(hProcess, INFINITE) == 0)
return !CreateProcessW(pathBuf.ptr, null, null, null, false, 0x04000608, null, null, si, pi);
}
return -1;
}
extern (Windows)
{
BOOL SendMessageW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
HWND FindWindowW(LPCWSTR lpClassName, LPCWSTR lpWindowName);
BOOL CreateProcessW(in LPCWSTR, LPWSTR, in LPSECURITY_ATTRIBUTES, in LPSECURITY_ATTRIBUTES, in BOOL, in DWORD, in LPVOID, in LPCWSTR, ref STARTUPINFOW, out PROCESS_INFORMATION);
HANDLE OpenProcess(in DWORD dwDesiredAccess, in BOOL bInheritHandle, in DWORD dwProcessId);
DWORD GetWindowThreadProcessId(HWND hWnd, out DWORD lpdwProcessId);
DWORD ExpandEnvironmentStringsW(in LPCWSTR lpSrc, LPWSTR lpDst, in DWORD nSize);
}
Espero que ajude!