2019-12-25 08:15:39 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS api tests
|
|
|
|
* LICENSE: GPLv2+ - See COPYING in the top level directory
|
|
|
|
* PURPOSE: Testing ShellExecuteW
|
2020-02-14 14:04:17 +00:00
|
|
|
* PROGRAMMERS: Doug Lyons <douglyons@douglyons.com>
|
|
|
|
* Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
|
2019-12-25 08:15:39 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "shelltest.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <winbase.h>
|
2020-02-14 14:04:17 +00:00
|
|
|
#include <shlwapi.h>
|
2019-12-25 08:15:39 +00:00
|
|
|
|
2020-02-14 14:04:17 +00:00
|
|
|
#define WAIT_SLEEP 700
|
|
|
|
|
|
|
|
// ShellExecuteW(handle, "open", <path_to_executable>, <parameters>, NULL, SW_SHOWNORMAL);
|
|
|
|
|
|
|
|
START_TEST(ShellExecuteW)
|
2019-12-25 08:15:39 +00:00
|
|
|
{
|
2020-02-14 14:04:17 +00:00
|
|
|
INT ret;
|
2019-12-25 08:15:39 +00:00
|
|
|
HINSTANCE hInstance;
|
|
|
|
HWND hWnd;
|
2020-02-14 14:04:17 +00:00
|
|
|
WCHAR WinDir[MAX_PATH], SysDir[MAX_PATH], SysDrive[MAX_PATH];
|
2019-12-25 08:15:39 +00:00
|
|
|
|
2020-02-14 14:04:17 +00:00
|
|
|
if (!GetWindowsDirectoryW(WinDir, _countof(WinDir)))
|
|
|
|
{
|
|
|
|
skip("GetWindowsDirectoryW failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!GetSystemDirectoryW(SysDir, _countof(SysDir)))
|
|
|
|
{
|
|
|
|
skip("GetSystemDirectoryW failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!GetEnvironmentVariableW(L"SystemDrive", SysDrive, _countof(SysDrive)))
|
|
|
|
{
|
|
|
|
trace("GetEnvironmentVariableW('SystemDrive') failed\n");
|
|
|
|
SysDrive[0] = SysDir[0];
|
|
|
|
SysDrive[1] = L':';
|
|
|
|
SysDrive[2] = 0;
|
|
|
|
}
|
|
|
|
PathAddBackslashW(SysDrive);
|
2019-12-25 08:15:39 +00:00
|
|
|
|
2020-02-14 14:04:17 +00:00
|
|
|
// TEST #1: Open Control Panel
|
2019-12-25 08:15:39 +00:00
|
|
|
hInstance = ShellExecuteW(NULL, L"open", L"rundll32.exe", L"shell32.dll,Control_RunDLL desk.cpl",
|
|
|
|
NULL, SW_SHOWNORMAL);
|
2020-02-14 14:04:17 +00:00
|
|
|
ret = (INT)(UINT_PTR)hInstance;
|
|
|
|
ok(ret > 31, "TEST #1: ret:%d, LastError: %ld\n", ret, GetLastError());
|
|
|
|
trace("TEST #1 ret: %d.\n", ret);
|
2019-12-25 08:15:39 +00:00
|
|
|
if (hInstance)
|
|
|
|
{
|
2020-02-14 14:04:17 +00:00
|
|
|
Sleep(WAIT_SLEEP);
|
|
|
|
// Terminate Window
|
|
|
|
hWnd = FindWindowW(NULL, L"Display Properties");
|
|
|
|
PostMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0);
|
2019-12-25 08:15:39 +00:00
|
|
|
}
|
|
|
|
|
2020-02-14 14:04:17 +00:00
|
|
|
// TEST #2: Open Notepad
|
2019-12-25 08:15:39 +00:00
|
|
|
hInstance = ShellExecuteW(NULL, L"open", L"notepad.exe", NULL, NULL, SW_SHOWNORMAL);
|
2020-02-14 14:04:17 +00:00
|
|
|
ret = (INT)(UINT_PTR)hInstance;
|
|
|
|
ok(ret > 31, "TEST #2: ret:%d, LastError: %ld\n", ret, GetLastError());
|
|
|
|
trace("TEST #2 ret: %d.\n", ret);
|
2019-12-25 08:15:39 +00:00
|
|
|
if (hInstance)
|
|
|
|
{
|
2020-02-14 14:04:17 +00:00
|
|
|
Sleep(WAIT_SLEEP);
|
|
|
|
// Terminate Window
|
|
|
|
hWnd = FindWindowW(L"Notepad", L"Untitled - Notepad");
|
|
|
|
PostMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0);
|
2019-12-25 08:15:39 +00:00
|
|
|
}
|
|
|
|
|
2020-02-14 14:04:17 +00:00
|
|
|
// TEST #3: Open Windows folder
|
|
|
|
hInstance = ShellExecuteW(NULL, NULL, WinDir, NULL, NULL, SW_SHOWNORMAL);
|
|
|
|
ret = (INT)(UINT_PTR)hInstance;
|
|
|
|
ok(ret > 31, "TEST #3: ret:%d, LastError: %ld\n", ret, GetLastError());
|
|
|
|
trace("TEST #3 ret: %d.\n", ret);
|
2019-12-25 08:15:39 +00:00
|
|
|
if (hInstance)
|
|
|
|
{
|
2020-02-14 14:04:17 +00:00
|
|
|
Sleep(WAIT_SLEEP);
|
|
|
|
// Terminate Window
|
|
|
|
hWnd = FindWindowW(L"CabinetWClass", WinDir);
|
|
|
|
PostMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0);
|
2019-12-25 08:15:39 +00:00
|
|
|
}
|
|
|
|
|
2020-02-14 14:04:17 +00:00
|
|
|
// TEST #4: Open system32 folder
|
|
|
|
hInstance = ShellExecuteW(NULL, L"open", SysDir, NULL, NULL, SW_SHOWNORMAL);
|
|
|
|
ret = (INT)(UINT_PTR)hInstance;
|
|
|
|
ok(ret > 31, "TEST #4: ret:%d, LastError: %ld\n", ret, GetLastError());
|
|
|
|
trace("TEST #4 ret: %d.\n", ret);
|
2019-12-25 08:15:39 +00:00
|
|
|
if (hInstance)
|
|
|
|
{
|
2020-02-14 14:04:17 +00:00
|
|
|
Sleep(WAIT_SLEEP);
|
|
|
|
// Terminate Window
|
|
|
|
hWnd = FindWindowW(L"CabinetWClass", SysDir);
|
|
|
|
PostMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0);
|
2019-12-25 08:15:39 +00:00
|
|
|
}
|
|
|
|
|
2020-02-14 14:04:17 +00:00
|
|
|
// TEST #5: Open %SystemDrive%
|
|
|
|
hInstance = ShellExecuteW(NULL, L"explore", SysDrive, NULL, NULL, SW_SHOWNORMAL);
|
|
|
|
ret = (INT)(UINT_PTR)hInstance;
|
|
|
|
ok(ret > 31, "TEST #5: ret:%d, LastError: %ld\n", ret, GetLastError());
|
|
|
|
trace("TEST #5 ret: %d.\n", ret);
|
2019-12-25 08:15:39 +00:00
|
|
|
if (hInstance)
|
|
|
|
{
|
2020-02-14 14:04:17 +00:00
|
|
|
Sleep(WAIT_SLEEP);
|
|
|
|
// Terminate Window
|
|
|
|
hWnd = FindWindowW(L"ExploreWClass", SysDrive);
|
|
|
|
PostMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0);
|
2019-12-25 08:15:39 +00:00
|
|
|
}
|
|
|
|
|
2020-02-14 14:04:17 +00:00
|
|
|
// TEST #6: Open Explorer Search on %SYSTEMDRIVE%
|
|
|
|
hInstance = ShellExecuteW(NULL, L"find", SysDrive, NULL, NULL, SW_SHOWNORMAL);
|
|
|
|
ret = (INT)(UINT_PTR)hInstance;
|
|
|
|
ok(ret > 31, "TEST #6: ret:%d, LastError: %ld\n", ret, GetLastError());
|
|
|
|
trace("TEST #6 ret: %d.\n", ret);
|
2019-12-25 08:15:39 +00:00
|
|
|
if (hInstance)
|
|
|
|
{
|
2020-02-14 14:04:17 +00:00
|
|
|
Sleep(WAIT_SLEEP);
|
|
|
|
// Terminate Window
|
|
|
|
hWnd = FindWindowW(L"CabinetWClass", L"Search Results");
|
|
|
|
PostMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0);
|
2019-12-25 08:15:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Windows Server 2003 and Windows XP SP3 return values (Win 7 returns 42 in all cases)
|
2020-02-14 14:04:17 +00:00
|
|
|
// ShellExecuteW(NULL, L"open", L"rundll32.exe", L"shell32.dll,Control_RunDLL desk.cpl", NULL, SW_SHOWNORMAL) = 42
|
|
|
|
// ShellExecuteW(NULL, L"open", L"notepad.exe", NULL, NULL, SW_SHOWNORMAL) = 42
|
|
|
|
// ShellExecuteW(NULL, NULL, WinDir, NULL, NULL, SW_SHOWNORMAL) = 33
|
|
|
|
// ShellExecuteW(NULL, L"open", SysDir, NULL, NULL, SW_SHOWNORMAL) = 33
|
|
|
|
// ShellExecuteW(NULL, L"explore", SysDrive, NULL, NULL, SW_SHOWNORMAL) = 33
|
|
|
|
// ShellExecuteW(NULL, L"find", SysDrive, NULL, NULL, SW_SHOWNORMAL) = 33
|