1 /* 2 * PROJECT: ReactOS api tests 3 * LICENSE: GPLv2+ - See COPYING in the top level directory 4 * PURPOSE: Testing ShellExecuteW 5 * PROGRAMMERS: Doug Lyons <douglyons@douglyons.com> 6 * Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com> 7 */ 8 9 #include "shelltest.h" 10 #include <stdio.h> 11 #include <winbase.h> 12 #include <shlwapi.h> 13 14 #define WAIT_SLEEP 700 15 16 // ShellExecuteW(handle, "open", <path_to_executable>, <parameters>, NULL, SW_SHOWNORMAL); 17 18 START_TEST(ShellExecuteW) 19 { 20 INT ret; 21 HINSTANCE hInstance; 22 HWND hWnd; 23 WCHAR WinDir[MAX_PATH], SysDir[MAX_PATH], SysDrive[MAX_PATH]; 24 25 if (!GetWindowsDirectoryW(WinDir, _countof(WinDir))) 26 { 27 skip("GetWindowsDirectoryW failed\n"); 28 return; 29 } 30 if (!GetSystemDirectoryW(SysDir, _countof(SysDir))) 31 { 32 skip("GetSystemDirectoryW failed\n"); 33 return; 34 } 35 if (!GetEnvironmentVariableW(L"SystemDrive", SysDrive, _countof(SysDrive))) 36 { 37 trace("GetEnvironmentVariableW('SystemDrive') failed\n"); 38 SysDrive[0] = SysDir[0]; 39 SysDrive[1] = L':'; 40 SysDrive[2] = 0; 41 } 42 PathAddBackslashW(SysDrive); 43 44 // TEST #1: Open Control Panel 45 hInstance = ShellExecuteW(NULL, L"open", L"rundll32.exe", L"shell32.dll,Control_RunDLL desk.cpl", 46 NULL, SW_SHOWNORMAL); 47 ret = (INT)(UINT_PTR)hInstance; 48 ok(ret > 31, "TEST #1: ret:%d, LastError: %ld\n", ret, GetLastError()); 49 trace("TEST #1 ret: %d.\n", ret); 50 if (hInstance) 51 { 52 Sleep(WAIT_SLEEP); 53 // Terminate Window 54 hWnd = FindWindowW(NULL, L"Display Properties"); 55 PostMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0); 56 } 57 58 // TEST #2: Open Notepad 59 hInstance = ShellExecuteW(NULL, L"open", L"notepad.exe", NULL, NULL, SW_SHOWNORMAL); 60 ret = (INT)(UINT_PTR)hInstance; 61 ok(ret > 31, "TEST #2: ret:%d, LastError: %ld\n", ret, GetLastError()); 62 trace("TEST #2 ret: %d.\n", ret); 63 if (hInstance) 64 { 65 Sleep(WAIT_SLEEP); 66 // Terminate Window 67 hWnd = FindWindowW(L"Notepad", L"Untitled - Notepad"); 68 PostMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0); 69 } 70 71 // TEST #3: Open Windows folder 72 hInstance = ShellExecuteW(NULL, NULL, WinDir, NULL, NULL, SW_SHOWNORMAL); 73 ret = (INT)(UINT_PTR)hInstance; 74 ok(ret > 31, "TEST #3: ret:%d, LastError: %ld\n", ret, GetLastError()); 75 trace("TEST #3 ret: %d.\n", ret); 76 if (hInstance) 77 { 78 Sleep(WAIT_SLEEP); 79 // Terminate Window 80 hWnd = FindWindowW(L"CabinetWClass", WinDir); 81 PostMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0); 82 } 83 84 // TEST #4: Open system32 folder 85 hInstance = ShellExecuteW(NULL, L"open", SysDir, NULL, NULL, SW_SHOWNORMAL); 86 ret = (INT)(UINT_PTR)hInstance; 87 ok(ret > 31, "TEST #4: ret:%d, LastError: %ld\n", ret, GetLastError()); 88 trace("TEST #4 ret: %d.\n", ret); 89 if (hInstance) 90 { 91 Sleep(WAIT_SLEEP); 92 // Terminate Window 93 hWnd = FindWindowW(L"CabinetWClass", SysDir); 94 PostMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0); 95 } 96 97 // TEST #5: Open %SystemDrive% 98 hInstance = ShellExecuteW(NULL, L"explore", SysDrive, NULL, NULL, SW_SHOWNORMAL); 99 ret = (INT)(UINT_PTR)hInstance; 100 ok(ret > 31, "TEST #5: ret:%d, LastError: %ld\n", ret, GetLastError()); 101 trace("TEST #5 ret: %d.\n", ret); 102 if (hInstance) 103 { 104 Sleep(WAIT_SLEEP); 105 // Terminate Window 106 hWnd = FindWindowW(L"ExploreWClass", SysDrive); 107 PostMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0); 108 } 109 110 // TEST #6: Open Explorer Search on %SYSTEMDRIVE% 111 hInstance = ShellExecuteW(NULL, L"find", SysDrive, NULL, NULL, SW_SHOWNORMAL); 112 ret = (INT)(UINT_PTR)hInstance; 113 ok(ret > 31, "TEST #6: ret:%d, LastError: %ld\n", ret, GetLastError()); 114 trace("TEST #6 ret: %d.\n", ret); 115 if (hInstance) 116 { 117 Sleep(WAIT_SLEEP); 118 // Terminate Window 119 hWnd = FindWindowW(L"CabinetWClass", L"Search Results"); 120 PostMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0); 121 } 122 123 // TEST #7: Open My Documents ("::{450d8fba-ad25-11d0-98a8-0800361b1103}") 124 hInstance = ShellExecuteW(NULL, NULL, L"::{450d8fba-ad25-11d0-98a8-0800361b1103}", NULL, NULL, SW_SHOWNORMAL); 125 ret = (INT)(UINT_PTR)hInstance; 126 ok(ret > 31, "TEST #7: ret:%d, LastError: %ld\n", ret, GetLastError()); 127 trace("TEST #7 ret: %d.\n", ret); 128 if (hInstance) 129 { 130 Sleep(WAIT_SLEEP); 131 // Terminate Window 132 hWnd = FindWindowW(L"CabinetWClass", NULL); 133 PostMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0); 134 } 135 136 // TEST #8: Open My Documents ("shell:::{450d8fba-ad25-11d0-98a8-0800361b1103}") 137 hInstance = ShellExecuteW(NULL, L"open", L"shell:::{450d8fba-ad25-11d0-98a8-0800361b1103}", NULL, NULL, SW_SHOWNORMAL); 138 ret = (INT)(UINT_PTR)hInstance; 139 ok(ret > 31, "TEST #8: ret:%d, LastError: %ld\n", ret, GetLastError()); 140 trace("TEST #8 ret: %d.\n", ret); 141 if (hInstance) 142 { 143 Sleep(WAIT_SLEEP); 144 // Terminate Window 145 hWnd = FindWindowW(L"CabinetWClass", NULL); 146 PostMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0); 147 } 148 } 149 150 // Windows Server 2003 and Windows XP SP3 return values (Win 7 returns 42 in all cases) 151 // ShellExecuteW(NULL, L"open", L"rundll32.exe", L"shell32.dll,Control_RunDLL desk.cpl", NULL, SW_SHOWNORMAL) = 42 152 // ShellExecuteW(NULL, L"open", L"notepad.exe", NULL, NULL, SW_SHOWNORMAL) = 42 153 // ShellExecuteW(NULL, NULL, WinDir, NULL, NULL, SW_SHOWNORMAL) = 33 154 // ShellExecuteW(NULL, L"open", SysDir, NULL, NULL, SW_SHOWNORMAL) = 33 155 // ShellExecuteW(NULL, L"explore", SysDrive, NULL, NULL, SW_SHOWNORMAL) = 33 156 // ShellExecuteW(NULL, L"find", SysDrive, NULL, NULL, SW_SHOWNORMAL) = 33 157