ReactOS  0.4.15-dev-1070-ge1a01de
ShellExecuteEx.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 ShellExecuteEx
5  * PROGRAMMER: Yaroslav Veremenko <yaroslav@veremenko.info>
6  */
7 
8 #include "shelltest.h"
9 
10 #define ok_ShellExecuteEx (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : TestShellExecuteEx
11 
12 static
13 BOOL
15 {
16  HKEY RegistryKey;
17  LONG Result;
18  WCHAR Buffer[1024];
19  WCHAR KeyValue[1024];
20  DWORD Length = sizeof(KeyValue);
22 
23  wcscpy(Buffer, L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\");
24  wcscat(Buffer, L"IEXPLORE.EXE");
26  if (Result != ERROR_SUCCESS) trace("Could not open iexplore.exe key. Status: %lu\n", Result);
27  if (Result) goto end;
28  Result = RegQueryValueExW(RegistryKey, NULL, NULL, NULL, (LPBYTE)KeyValue, &Length);
29  if (Result != ERROR_SUCCESS) trace("Could not read iexplore.exe key. Status: %lu\n", Result);
30  if (Result) goto end;
31  RegCloseKey(RegistryKey);
32 
33  wcscpy(Buffer, L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\");
34  wcscat(Buffer, Name);
36  0, KEY_WRITE, NULL, &RegistryKey, &Disposition);
37  if (Result != ERROR_SUCCESS) trace("Could not create test key. Status: %lu\n", Result);
38  if (Result) goto end;
39  Result = RegSetValueW(RegistryKey, NULL, REG_SZ, KeyValue, 0);
40  if (Result != ERROR_SUCCESS) trace("Could not set value of the test key. Status: %lu\n", Result);
41  if (Result) goto end;
42  RegCloseKey(RegistryKey);
43 end:
44  if (RegistryKey) RegCloseKey(RegistryKey);
45  return Result == ERROR_SUCCESS;
46 }
47 
48 static
49 VOID
51 {
52  LONG Result;
53  WCHAR Buffer[1024];
54  wcscpy(Buffer, L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\");
55  wcscat(Buffer, Name);
57  if (Result != ERROR_SUCCESS) trace("Could not remove the test key. Status: %lu\n", Result);
58 }
59 
60 static
61 VOID
62 TestShellExecuteEx(const WCHAR* Name, BOOL ExpectedResult)
63 {
64  SHELLEXECUTEINFOW ShellExecInfo;
65  BOOL Result;
66  ZeroMemory(&ShellExecInfo, sizeof(ShellExecInfo));
67  ShellExecInfo.cbSize = sizeof(ShellExecInfo);
69  ShellExecInfo.hwnd = NULL;
70  ShellExecInfo.nShow = SW_SHOWNORMAL;
71  ShellExecInfo.lpFile = Name;
72  ShellExecInfo.lpDirectory = NULL;
73  Result = ShellExecuteExW(&ShellExecInfo);
74  ok(Result == ExpectedResult, "ShellExecuteEx lpFile %s failed. Error: %lu\n", wine_dbgstr_w(Name), GetLastError());
75  if (ShellExecInfo.hProcess)
76  {
77  Result = TerminateProcess(ShellExecInfo.hProcess, 0);
78  if (!Result) trace("Terminate process failed. Error: %lu\n", GetLastError());
79  WaitForSingleObject(ShellExecInfo.hProcess, INFINITE);
80  CloseHandle(ShellExecInfo.hProcess);
81  }
82 }
83 
85 {
86  ok_ShellExecuteEx(L"iexplore", TRUE);
87  ok_ShellExecuteEx(L"iexplore.exe", TRUE);
88 
89  if (CreateAppPathRegKey(L"iexplore.bat"))
90  {
91  ok_ShellExecuteEx(L"iexplore.bat", TRUE);
92  ok_ShellExecuteEx(L"iexplore.bat.exe", FALSE);
93  DeleteAppPathRegKey(L"iexplore.bat");
94  }
95 
96  if (CreateAppPathRegKey(L"iexplore.bat.exe"))
97  {
98  ok_ShellExecuteEx(L"iexplore.bat", FALSE);
99  ok_ShellExecuteEx(L"iexplore.bat.exe", TRUE);
100  DeleteAppPathRegKey(L"iexplore.bat.exe");
101  }
102 }
#define ok_ShellExecuteEx
#define ShellExecuteEx
Definition: shellapi.h:692
#define CloseHandle
Definition: compat.h:487
static VOID DeleteAppPathRegKey(const WCHAR *Name)
#define ERROR_SUCCESS
Definition: deptool.c:10
#define SEE_MASK_NOCLOSEPROCESS
Definition: shellapi.h:31
#define KEY_READ
Definition: nt_native.h:1023
#define TRUE
Definition: types.h:120
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
LONG WINAPI RegDeleteKeyW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey)
Definition: reg.c:1237
LONG WINAPI RegSetValueW(HKEY hKeyOriginal, LPCWSTR lpSubKey, DWORD dwType, LPCWSTR lpData, DWORD cbData)
Definition: reg.c:5014
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
#define ZeroMemory
Definition: winbase.h:1648
GLuint GLuint end
Definition: gl.h:1545
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:50
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1091
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:53
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
LPCWSTR lpDirectory
Definition: shellapi.h:332
struct NameRec_ * Name
Definition: cdprocs.h:459
smooth NULL
Definition: ftsmooth.c:416
#define SEE_MASK_FLAG_NO_UI
Definition: shellapi.h:36
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
static VOID TestShellExecuteEx(const WCHAR *Name, BOOL ExpectedResult)
BOOL WINAPI DECLSPEC_HOTPATCH ShellExecuteExW(LPSHELLEXECUTEINFOW sei)
Definition: shlexec.cpp:2263
Definition: bufpool.h:45
#define KEY_WRITE
Definition: nt_native.h:1031
#define trace
Definition: atltest.h:70
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
#define SW_SHOWNORMAL
Definition: winuser.h:764
START_TEST(ShellExecuteEx)
BOOL WINAPI TerminateProcess(IN HANDLE hProcess, IN UINT uExitCode)
Definition: proc.c:1532
#define ok(value,...)
Definition: atltest.h:57
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
#define INFINITE
Definition: serial.h:102
static BOOL CreateAppPathRegKey(const WCHAR *Name)
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define REG_SZ
Definition: layer.c:22