ReactOS 0.4.15-dev-7131-ge4d03f4
ShellExecuteW.cpp
Go to the documentation of this file.
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
19{
20 INT ret;
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",
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 {
53 // Terminate Window
54 hWnd = FindWindowW(NULL, L"Display Properties");
56 }
57
58 // TEST #2: Open Notepad
59 hInstance = ShellExecuteW(NULL, L"open", L"notepad.exe", NULL, NULL, SW_SHOWNORMAL);
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 {
66 // Terminate Window
67 hWnd = FindWindowW(L"Notepad", L"Untitled - Notepad");
69 }
70
71 // TEST #3: Open Windows folder
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 {
79 // Terminate Window
80 hWnd = FindWindowW(L"CabinetWClass", WinDir);
82 }
83
84 // TEST #4: Open system32 folder
85 hInstance = ShellExecuteW(NULL, L"open", SysDir, NULL, NULL, SW_SHOWNORMAL);
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 {
92 // Terminate Window
93 hWnd = FindWindowW(L"CabinetWClass", SysDir);
95 }
96
97 // TEST #5: Open %SystemDrive%
98 hInstance = ShellExecuteW(NULL, L"explore", SysDrive, NULL, NULL, SW_SHOWNORMAL);
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 {
105 // Terminate Window
106 hWnd = FindWindowW(L"ExploreWClass", SysDrive);
108 }
109
110 // TEST #6: Open Explorer Search on %SYSTEMDRIVE%
111 hInstance = ShellExecuteW(NULL, L"find", SysDrive, NULL, NULL, SW_SHOWNORMAL);
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 {
118 // Terminate Window
119 hWnd = FindWindowW(L"CabinetWClass", L"Search Results");
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);
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 {
131 // Terminate Window
132 hWnd = FindWindowW(L"CabinetWClass", NULL);
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);
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 {
144 // Terminate Window
145 hWnd = FindWindowW(L"CabinetWClass", NULL);
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
#define WAIT_SLEEP
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
HWND hWnd
Definition: settings.c:17
HINSTANCE hInstance
Definition: charmap.c:19
#define NULL
Definition: types.h:112
#define GetEnvironmentVariableW(x, y, z)
Definition: compat.h:755
#define MAX_PATH
Definition: compat.h:34
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2313
UINT WINAPI GetWindowsDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2352
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
#define L(x)
Definition: ntvdm.h:50
#define PathAddBackslashW
Definition: pathcch.h:301
#define INT
Definition: polytest.cpp:20
HINSTANCE WINAPI ShellExecuteW(HWND hwnd, LPCWSTR lpVerb, LPCWSTR lpFile, LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd)
Definition: shlexec.cpp:2379
#define _countof(array)
Definition: sndvol32.h:68
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
int32_t INT
Definition: typedefs.h:58
int ret
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define SW_SHOWNORMAL
Definition: winuser.h:769
#define WM_SYSCOMMAND
Definition: winuser.h:1740
#define SC_CLOSE
Definition: winuser.h:2591
#define PostMessage
Definition: winuser.h:5831
HWND WINAPI FindWindowW(_In_opt_ LPCWSTR, _In_opt_ LPCWSTR)
__wchar_t WCHAR
Definition: xmlstorage.h:180