schtasks/tests: Deleting folders requires elevated privileges on Windows 7 & 8.

This means skipping any test that requires creating a task as the test
would be unable to clean up after itself.

Wine-Bug: https://bugs.winehq.org//show_bug.cgi?id=52193
Wine-Bug: https://bugs.winehq.org//show_bug.cgi?id=54634
This commit is contained in:
Francois Gouget 2023-03-25 17:52:59 +01:00 committed by Alexandre Julliard
parent d0246c3ea0
commit 739c5c547c
2 changed files with 41 additions and 1 deletions

View file

@ -1,5 +1,5 @@
TESTDLL = schtasks.exe TESTDLL = schtasks.exe
IMPORTS = ole32 IMPORTS = advapi32 ole32
C_SRCS = \ C_SRCS = \

View file

@ -16,8 +16,11 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
#include <stdarg.h>
#define COBJMACROS #define COBJMACROS
#include "winternl.h"
#include "initguid.h" #include "initguid.h"
#include "taskschd.h" #include "taskschd.h"
@ -58,6 +61,37 @@ static WCHAR *a2w(const char *str)
return ret; return ret;
} }
static BOOL is_process_elevated(void)
{
HANDLE token;
if (OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY, &token ))
{
TOKEN_ELEVATION_TYPE type;
DWORD size;
BOOL ret;
ret = GetTokenInformation( token, TokenElevationType, &type, sizeof(type), &size );
CloseHandle( token );
return (ret && type == TokenElevationTypeFull);
}
return FALSE;
}
static BOOL check_win_version(int min_major, int min_minor)
{
HMODULE hntdll = GetModuleHandleA("ntdll.dll");
NTSTATUS (WINAPI *pRtlGetVersion)(RTL_OSVERSIONINFOEXW *);
RTL_OSVERSIONINFOEXW rtlver;
rtlver.dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW);
pRtlGetVersion = (void *)GetProcAddress(hntdll, "RtlGetVersion");
pRtlGetVersion(&rtlver);
return rtlver.dwMajorVersion > min_major ||
(rtlver.dwMajorVersion == min_major &&
rtlver.dwMinorVersion >= min_minor);
}
#define is_win10_plus() check_win_version(10, 0)
#define run_command(a) _run_command(__LINE__,a) #define run_command(a) _run_command(__LINE__,a)
static DWORD _run_command(unsigned line, const char *cmd) static DWORD _run_command(unsigned line, const char *cmd)
{ {
@ -173,6 +207,12 @@ START_TEST(schtasks)
static WCHAR wine_testW[] = L"\\wine\\test"; static WCHAR wine_testW[] = L"\\wine\\test";
DWORD r; DWORD r;
if (!is_process_elevated() && !is_win10_plus())
{
win_skip("Deleting the test folders requires elevated privileges on Windows <= 8\n");
return;
}
CoInitialize(NULL); CoInitialize(NULL);
if(!initialize_task_service()) { if(!initialize_task_service()) {
CoUninitialize(); CoUninitialize();