1*c2c66affSColin Finck /* 2*c2c66affSColin Finck * PROJECT: ReactOS api tests 3*c2c66affSColin Finck * LICENSE: GPLv2+ - See COPYING in the top level directory 4*c2c66affSColin Finck * PURPOSE: Testing ShellExecuteEx 5*c2c66affSColin Finck * PROGRAMMER: Yaroslav Veremenko <yaroslav@veremenko.info> 6*c2c66affSColin Finck */ 7*c2c66affSColin Finck 8*c2c66affSColin Finck 9*c2c66affSColin Finck #include "shelltest.h" 10*c2c66affSColin Finck 11*c2c66affSColin Finck 12*c2c66affSColin Finck 13*c2c66affSColin Finck #define ok_ShellExecuteEx (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : TestShellExecuteEx 14*c2c66affSColin Finck 15*c2c66affSColin Finck static 16*c2c66affSColin Finck BOOL 17*c2c66affSColin Finck CreateAppPathRegKey(const WCHAR* Name) 18*c2c66affSColin Finck { 19*c2c66affSColin Finck HKEY RegistryKey; 20*c2c66affSColin Finck LONG Result; 21*c2c66affSColin Finck WCHAR Buffer[1024]; 22*c2c66affSColin Finck WCHAR KeyValue[1024]; 23*c2c66affSColin Finck DWORD Length = sizeof(KeyValue); 24*c2c66affSColin Finck DWORD Disposition; 25*c2c66affSColin Finck 26*c2c66affSColin Finck wcscpy(Buffer, L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\"); 27*c2c66affSColin Finck wcscat(Buffer, L"IEXPLORE.EXE"); 28*c2c66affSColin Finck Result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, Buffer, 0, KEY_READ, &RegistryKey); 29*c2c66affSColin Finck if (Result != ERROR_SUCCESS) trace("Could not open iexplore.exe key. Status: %lu\n", Result); 30*c2c66affSColin Finck if (Result) goto end; 31*c2c66affSColin Finck Result = RegQueryValueExW(RegistryKey, NULL, NULL, NULL, (LPBYTE)KeyValue, &Length); 32*c2c66affSColin Finck if (Result != ERROR_SUCCESS) trace("Could not read iexplore.exe key. Status: %lu\n", Result); 33*c2c66affSColin Finck if (Result) goto end; 34*c2c66affSColin Finck RegCloseKey(RegistryKey); 35*c2c66affSColin Finck 36*c2c66affSColin Finck wcscpy(Buffer, L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\"); 37*c2c66affSColin Finck wcscat(Buffer, Name); 38*c2c66affSColin Finck Result = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Buffer, 0, NULL, 39*c2c66affSColin Finck 0, KEY_WRITE, NULL, &RegistryKey, &Disposition); 40*c2c66affSColin Finck if (Result != ERROR_SUCCESS) trace("Could not create test key. Status: %lu\n", Result); 41*c2c66affSColin Finck if (Result) goto end; 42*c2c66affSColin Finck Result = RegSetValueW(RegistryKey, NULL, REG_SZ, KeyValue, 0); 43*c2c66affSColin Finck if (Result != ERROR_SUCCESS) trace("Could not set value of the test key. Status: %lu\n", Result); 44*c2c66affSColin Finck if (Result) goto end; 45*c2c66affSColin Finck RegCloseKey(RegistryKey); 46*c2c66affSColin Finck end: 47*c2c66affSColin Finck if (RegistryKey) RegCloseKey(RegistryKey); 48*c2c66affSColin Finck return Result == ERROR_SUCCESS; 49*c2c66affSColin Finck } 50*c2c66affSColin Finck 51*c2c66affSColin Finck static 52*c2c66affSColin Finck VOID 53*c2c66affSColin Finck DeleteAppPathRegKey(const WCHAR* Name) 54*c2c66affSColin Finck { 55*c2c66affSColin Finck LONG Result; 56*c2c66affSColin Finck WCHAR Buffer[1024]; 57*c2c66affSColin Finck wcscpy(Buffer, L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\"); 58*c2c66affSColin Finck wcscat(Buffer, Name); 59*c2c66affSColin Finck Result = RegDeleteKeyW(HKEY_LOCAL_MACHINE, Buffer); 60*c2c66affSColin Finck if (Result != ERROR_SUCCESS) trace("Could not remove the test key. Status: %lu\n", Result); 61*c2c66affSColin Finck } 62*c2c66affSColin Finck 63*c2c66affSColin Finck static 64*c2c66affSColin Finck VOID 65*c2c66affSColin Finck TestShellExecuteEx(const WCHAR* Name, BOOL ExpectedResult) 66*c2c66affSColin Finck { 67*c2c66affSColin Finck SHELLEXECUTEINFOW ShellExecInfo; 68*c2c66affSColin Finck BOOL Result; 69*c2c66affSColin Finck ZeroMemory(&ShellExecInfo, sizeof(ShellExecInfo)); 70*c2c66affSColin Finck ShellExecInfo.cbSize = sizeof(ShellExecInfo); 71*c2c66affSColin Finck ShellExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI; 72*c2c66affSColin Finck ShellExecInfo.hwnd = NULL; 73*c2c66affSColin Finck ShellExecInfo.nShow = SW_SHOWNORMAL; 74*c2c66affSColin Finck ShellExecInfo.lpFile = Name; 75*c2c66affSColin Finck ShellExecInfo.lpDirectory = NULL; 76*c2c66affSColin Finck Result = ShellExecuteExW(&ShellExecInfo); 77*c2c66affSColin Finck ok(Result == ExpectedResult, "ShellExecuteEx lpFile %s failed. Error: %lu\n", wine_dbgstr_w(Name), GetLastError()); 78*c2c66affSColin Finck if (ShellExecInfo.hProcess) 79*c2c66affSColin Finck { 80*c2c66affSColin Finck Result = TerminateProcess(ShellExecInfo.hProcess, 0); 81*c2c66affSColin Finck if (!Result) trace("Terminate process failed. Error: %lu\n", GetLastError()); 82*c2c66affSColin Finck WaitForSingleObject(ShellExecInfo.hProcess, INFINITE); 83*c2c66affSColin Finck CloseHandle(ShellExecInfo.hProcess); 84*c2c66affSColin Finck } 85*c2c66affSColin Finck } 86*c2c66affSColin Finck 87*c2c66affSColin Finck START_TEST(ShellExecuteEx) 88*c2c66affSColin Finck { 89*c2c66affSColin Finck ok_ShellExecuteEx(L"iexplore", TRUE); 90*c2c66affSColin Finck ok_ShellExecuteEx(L"iexplore.exe", TRUE); 91*c2c66affSColin Finck 92*c2c66affSColin Finck if (CreateAppPathRegKey(L"iexplore.bat")) 93*c2c66affSColin Finck { 94*c2c66affSColin Finck ok_ShellExecuteEx(L"iexplore.bat", TRUE); 95*c2c66affSColin Finck ok_ShellExecuteEx(L"iexplore.bat.exe", FALSE); 96*c2c66affSColin Finck DeleteAppPathRegKey(L"iexplore.bat"); 97*c2c66affSColin Finck } 98*c2c66affSColin Finck 99*c2c66affSColin Finck if (CreateAppPathRegKey(L"iexplore.bat.exe")) 100*c2c66affSColin Finck { 101*c2c66affSColin Finck ok_ShellExecuteEx(L"iexplore.bat", FALSE); 102*c2c66affSColin Finck ok_ShellExecuteEx(L"iexplore.bat.exe", TRUE); 103*c2c66affSColin Finck DeleteAppPathRegKey(L"iexplore.bat.exe"); 104*c2c66affSColin Finck } 105*c2c66affSColin Finck } 106