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