2 * Wine Conformance Test EXE
4 * Copyright 2003, 2004 Jakob Eriksson (for Solid Form Sweden AB)
5 * Copyright 2003 Dimitrie O. Paun
6 * Copyright 2003 Ferenc Wagner
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * This program is dedicated to Anna Lindh,
23 * Swedish Minister of Foreign Affairs.
24 * Anna was murdered September 11, 2003.
29 #include "wine/port.h"
41 /* Don't submit the results if more than SKIP_LIMIT tests have been skipped */
44 /* Don't submit the results if more than FAILURES_LIMIT tests have failed */
45 #define FAILURES_LIMIT 50
57 char *description
= NULL
;
60 BOOL aborting
= FALSE
;
61 static struct wine_test
*wine_tests
;
62 static int nr_of_files
, nr_of_tests
, nr_of_skips
;
63 static int nr_native_dlls
;
64 static const char whitespace
[] = " \t\r\n";
65 static const char testexe
[] = "_test.exe";
66 static char build_id
[64];
70 /* filters for running only specific tests */
71 static char *filters
[64];
72 static unsigned int nb_filters
= 0;
73 static BOOL exclude_tests
= FALSE
;
75 /* Needed to check for .NET dlls */
76 static HMODULE hmscoree
;
77 static HRESULT (WINAPI
*pLoadLibraryShim
)(LPCWSTR
, LPCWSTR
, LPVOID
, HMODULE
*);
79 /* For SxS DLLs e.g. msvcr90 */
80 static HANDLE (WINAPI
*pCreateActCtxA
)(PACTCTXA
);
81 static BOOL (WINAPI
*pActivateActCtx
)(HANDLE
, ULONG_PTR
*);
82 static BOOL (WINAPI
*pDeactivateActCtx
)(DWORD
, ULONG_PTR
);
83 static void (WINAPI
*pReleaseActCtx
)(HANDLE
);
85 /* To store the current PATH setting (related to .NET only provided dlls) */
88 /* check if test is being filtered out */
89 static BOOL
test_filtered_out( LPCSTR module
, LPCSTR testname
)
91 char *p
, dllname
[MAX_PATH
];
94 strcpy( dllname
, module
);
95 CharLowerA( dllname
);
96 p
= strstr( dllname
, testexe
);
98 len
= strlen(dllname
);
100 if (!nb_filters
) return exclude_tests
;
101 for (i
= 0; i
< nb_filters
; i
++)
103 if (!strncmp( dllname
, filters
[i
], len
))
105 if (!filters
[i
][len
]) return exclude_tests
;
106 if (filters
[i
][len
] != ':') continue;
107 if (testname
&& !strcmp( testname
, &filters
[i
][len
+1] )) return exclude_tests
;
108 if (!testname
&& !exclude_tests
) return FALSE
;
111 return !exclude_tests
;
114 static char * get_file_version(char * file_name
)
116 static char version
[32];
120 size
= GetFileVersionInfoSizeA(file_name
, &handle
);
122 char * data
= heap_alloc(size
);
124 if (GetFileVersionInfoA(file_name
, handle
, size
, data
)) {
125 static const char backslash
[] = "\\";
126 VS_FIXEDFILEINFO
*pFixedVersionInfo
;
128 if (VerQueryValueA(data
, backslash
, (LPVOID
*)&pFixedVersionInfo
, &len
)) {
129 sprintf(version
, "%d.%d.%d.%d",
130 pFixedVersionInfo
->dwFileVersionMS
>> 16,
131 pFixedVersionInfo
->dwFileVersionMS
& 0xffff,
132 pFixedVersionInfo
->dwFileVersionLS
>> 16,
133 pFixedVersionInfo
->dwFileVersionLS
& 0xffff);
135 sprintf(version
, "version not available");
137 sprintf(version
, "unknown");
140 sprintf(version
, "failed");
142 sprintf(version
, "version not available");
147 static BOOL
running_under_wine (void)
149 HMODULE module
= GetModuleHandleA("ntdll.dll");
151 if (!module
) return FALSE
;
152 return (GetProcAddress(module
, "wine_server_call") != NULL
);
155 static BOOL
check_mount_mgr(void)
157 HANDLE handle
= CreateFileA( "\\\\.\\MountPointManager", GENERIC_READ
,
158 FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, 0 );
159 if (handle
== INVALID_HANDLE_VALUE
) return FALSE
;
160 CloseHandle( handle
);
164 static BOOL
check_wow64_registry(void)
166 char buffer
[MAX_PATH
];
167 DWORD type
, size
= MAX_PATH
;
171 if (!is_wow64
) return TRUE
;
172 if (RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Microsoft\\Windows\\CurrentVersion", &hkey
))
174 ret
= !RegQueryValueExA( hkey
, "ProgramFilesDir (x86)", NULL
, &type
, (BYTE
*)buffer
, &size
);
179 static BOOL
check_display_driver(void)
181 HWND hwnd
= CreateWindowA( "STATIC", "", WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, 0, CW_USEDEFAULT
, 0,
182 0, 0, GetModuleHandleA(0), 0 );
183 if (!hwnd
) return FALSE
;
184 DestroyWindow( hwnd
);
188 static BOOL
running_on_visible_desktop (void)
191 HMODULE huser32
= GetModuleHandleA("user32.dll");
192 HWINSTA (WINAPI
*pGetProcessWindowStation
)(void);
193 BOOL (WINAPI
*pGetUserObjectInformationA
)(HANDLE
,INT
,LPVOID
,DWORD
,LPDWORD
);
195 pGetProcessWindowStation
= (void *)GetProcAddress(huser32
, "GetProcessWindowStation");
196 pGetUserObjectInformationA
= (void *)GetProcAddress(huser32
, "GetUserObjectInformationA");
198 desktop
= GetDesktopWindow();
199 if (!GetWindowLongPtrW(desktop
, GWLP_WNDPROC
)) /* Win9x */
200 return IsWindowVisible(desktop
);
202 if (pGetProcessWindowStation
&& pGetUserObjectInformationA
)
206 USEROBJECTFLAGS uoflags
;
208 wstation
= (HWINSTA
)pGetProcessWindowStation();
209 assert(pGetUserObjectInformationA(wstation
, UOI_FLAGS
, &uoflags
, sizeof(uoflags
), &len
));
210 return (uoflags
.dwFlags
& WSF_VISIBLE
) != 0;
212 return IsWindowVisible(desktop
);
215 static int running_as_admin (void)
217 PSID administrators
= NULL
;
218 SID_IDENTIFIER_AUTHORITY nt_authority
= { SECURITY_NT_AUTHORITY
};
221 PTOKEN_GROUPS groups
;
224 /* Create a well-known SID for the Administrators group. */
225 if (! AllocateAndInitializeSid(&nt_authority
, 2, SECURITY_BUILTIN_DOMAIN_RID
,
226 DOMAIN_ALIAS_RID_ADMINS
, 0, 0, 0, 0, 0, 0,
230 /* Get the process token */
231 if (! OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY
, &token
))
233 FreeSid(administrators
);
237 /* Get the group info from the token */
239 GetTokenInformation(token
, TokenGroups
, NULL
, 0, &groups_size
);
240 groups
= heap_alloc(groups_size
);
244 FreeSid(administrators
);
247 if (! GetTokenInformation(token
, TokenGroups
, groups
, groups_size
, &groups_size
))
251 FreeSid(administrators
);
256 /* Now check if the token groups include the Administrators group */
257 for (group_index
= 0; group_index
< groups
->GroupCount
; group_index
++)
259 if (EqualSid(groups
->Groups
[group_index
].Sid
, administrators
))
262 FreeSid(administrators
);
267 /* If we end up here we didn't find the Administrators group */
269 FreeSid(administrators
);
273 static int running_elevated (void)
276 TOKEN_ELEVATION elevation_info
;
279 /* Get the process token */
280 if (! OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY
, &token
))
283 /* Get the elevation info from the token */
284 if (! GetTokenInformation(token
, TokenElevation
, &elevation_info
,
285 sizeof(TOKEN_ELEVATION
), &size
))
292 return elevation_info
.TokenIsElevated
;
295 /* check for native dll when running under wine */
296 static BOOL
is_native_dll( HMODULE module
)
298 static const char fakedll_signature
[] = "Wine placeholder DLL";
299 const IMAGE_DOS_HEADER
*dos
;
301 if (!running_under_wine()) return FALSE
;
302 if (!((ULONG_PTR
)module
& 1)) return FALSE
; /* not loaded as datafile */
303 /* builtin dlls can't be loaded as datafile, so we must have native or fake dll */
304 dos
= (const IMAGE_DOS_HEADER
*)((const char *)module
- 1);
305 if (dos
->e_magic
!= IMAGE_DOS_SIGNATURE
) return FALSE
;
306 if (dos
->e_lfanew
>= sizeof(*dos
) + sizeof(fakedll_signature
) &&
307 !memcmp( dos
+ 1, fakedll_signature
, sizeof(fakedll_signature
) )) return FALSE
;
312 * Windows 8 has a concept of stub DLLs. When DLLMain is called the user is prompted
313 * to install that component. To bypass this check we need to look at the version resource.
315 static BOOL
is_stub_dll(const char *filename
)
321 size
= GetFileVersionInfoSizeA(filename
, &ver
);
322 if (!size
) return FALSE
;
324 data
= HeapAlloc(GetProcessHeap(), 0, size
);
325 if (!data
) return FALSE
;
327 if (GetFileVersionInfoA(filename
, ver
, size
, data
))
331 sprintf(buf
, "\\StringFileInfo\\%04x%04x\\OriginalFilename", MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), 1200);
332 if (VerQueryValueA(data
, buf
, (void**)&p
, &size
))
333 isstub
= !lstrcmpiA("wcodstub.dll", p
);
335 HeapFree(GetProcessHeap(), 0, data
);
340 static void print_version (void)
343 static const char platform
[] = "i386";
344 #elif defined(__x86_64__)
345 static const char platform
[] = "x86_64";
346 #elif defined(__powerpc__)
347 static const char platform
[] = "powerpc";
348 #elif defined(__arm__)
349 static const char platform
[] = "arm";
350 #elif defined(__aarch64__)
351 static const char platform
[] = "arm64";
355 OSVERSIONINFOEXA ver
;
356 RTL_OSVERSIONINFOEXW rtlver
;
358 int is_win2k3_r2
, is_admin
, is_elevated
;
359 const char *(CDECL
*wine_get_build_id
)(void);
360 HMODULE hntdll
= GetModuleHandleA("ntdll.dll");
361 void (CDECL
*wine_get_host_version
)( const char **sysname
, const char **release
);
362 BOOL (WINAPI
*pGetProductInfo
)(DWORD
, DWORD
, DWORD
, DWORD
, DWORD
*);
363 NTSTATUS (WINAPI
*pRtlGetVersion
)(RTL_OSVERSIONINFOEXW
*);
365 ver
.dwOSVersionInfoSize
= sizeof(ver
);
366 if (!(ext
= GetVersionExA ((OSVERSIONINFOA
*) &ver
)))
368 ver
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOA
);
369 if (!GetVersionExA ((OSVERSIONINFOA
*) &ver
))
370 report (R_FATAL
, "Can't get OS version.");
373 /* try to get non-faked values */
374 if (ver
.dwMajorVersion
== 6 && ver
.dwMinorVersion
== 2)
376 rtlver
.dwOSVersionInfoSize
= sizeof(RTL_OSVERSIONINFOEXW
);
378 pRtlGetVersion
= (void *)GetProcAddress(hntdll
, "RtlGetVersion");
379 pRtlGetVersion(&rtlver
);
381 ver
.dwMajorVersion
= rtlver
.dwMajorVersion
;
382 ver
.dwMinorVersion
= rtlver
.dwMinorVersion
;
383 ver
.dwBuildNumber
= rtlver
.dwBuildNumber
;
384 ver
.dwPlatformId
= rtlver
.dwPlatformId
;
385 ver
.wServicePackMajor
= rtlver
.wServicePackMajor
;
386 ver
.wServicePackMinor
= rtlver
.wServicePackMinor
;
387 ver
.wSuiteMask
= rtlver
.wSuiteMask
;
388 ver
.wProductType
= rtlver
.wProductType
;
390 WideCharToMultiByte(CP_ACP
, 0, rtlver
.szCSDVersion
, -1, ver
.szCSDVersion
, sizeof(ver
.szCSDVersion
), NULL
, NULL
);
393 xprintf (" Platform=%s%s\n", platform
, is_wow64
? " (WOW64)" : "");
394 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
395 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
396 is_admin
= running_as_admin ();
399 xprintf (" Account=%s", is_admin
? "admin" : "non-admin");
400 is_elevated
= running_elevated ();
401 if (0 <= is_elevated
)
402 xprintf(", %s", is_elevated
? "elevated" : "not elevated");
405 xprintf (" Submitter=%s\n", email
);
407 xprintf (" Description=%s\n", description
);
409 xprintf (" URL=%s\n", url
);
410 xprintf (" dwMajorVersion=%u\n dwMinorVersion=%u\n"
411 " dwBuildNumber=%u\n PlatformId=%u\n szCSDVersion=%s\n",
412 ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.dwBuildNumber
,
413 ver
.dwPlatformId
, ver
.szCSDVersion
);
415 wine_get_build_id
= (void *)GetProcAddress(hntdll
, "wine_get_build_id");
416 wine_get_host_version
= (void *)GetProcAddress(hntdll
, "wine_get_host_version");
417 if (wine_get_build_id
) xprintf( " WineBuild=%s\n", wine_get_build_id() );
418 if (wine_get_host_version
)
420 const char *sysname
, *release
;
421 wine_get_host_version( &sysname
, &release
);
422 xprintf( " Host system=%s\n Host version=%s\n", sysname
, release
);
424 is_win2k3_r2
= GetSystemMetrics(SM_SERVERR2
);
426 xprintf(" R2 build number=%d\n", is_win2k3_r2
);
430 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
431 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
432 ver
.wServicePackMajor
, ver
.wServicePackMinor
, ver
.wSuiteMask
,
433 ver
.wProductType
, ver
.wReserved
);
435 pGetProductInfo
= (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"GetProductInfo");
436 if (pGetProductInfo
&& !running_under_wine())
440 pGetProductInfo(ver
.dwMajorVersion
, ver
.dwMinorVersion
, ver
.wServicePackMajor
, ver
.wServicePackMinor
, &prodtype
);
441 xprintf(" dwProductInfo=%u\n", prodtype
);
445 static void print_language(void)
448 BOOL (WINAPI
*pGetSystemPreferredUILanguages
)(DWORD
, PULONG
, PZZWSTR
, PULONG
);
449 LANGID (WINAPI
*pGetUserDefaultUILanguage
)(void);
450 LANGID (WINAPI
*pGetThreadUILanguage
)(void);
452 xprintf (" SystemDefaultLCID=%04x\n", GetSystemDefaultLCID());
453 xprintf (" UserDefaultLCID=%04x\n", GetUserDefaultLCID());
454 xprintf (" ThreadLocale=%04x\n", GetThreadLocale());
456 hkernel32
= GetModuleHandleA("kernel32.dll");
457 pGetSystemPreferredUILanguages
= (void*)GetProcAddress(hkernel32
, "GetSystemPreferredUILanguages");
458 pGetUserDefaultUILanguage
= (void*)GetProcAddress(hkernel32
, "GetUserDefaultUILanguage");
459 pGetThreadUILanguage
= (void*)GetProcAddress(hkernel32
, "GetThreadUILanguage");
461 if (pGetSystemPreferredUILanguages
&& !running_under_wine())
464 ULONG num
, size
= sizeof(langW
)/sizeof(langW
[0]);
465 if (pGetSystemPreferredUILanguages(MUI_LANGUAGE_ID
, &num
, langW
, &size
))
467 char lang
[32], *p
= lang
;
468 WideCharToMultiByte(CP_ACP
, 0, langW
, size
, lang
, sizeof(lang
), NULL
, NULL
);
469 for (p
+= strlen(p
) + 1; *p
!= '\0'; p
+= strlen(p
) + 1) *(p
- 1) = ',';
470 xprintf (" SystemPreferredUILanguages=%s\n", lang
);
473 if (pGetUserDefaultUILanguage
)
474 xprintf (" UserDefaultUILanguage=%04x\n", pGetUserDefaultUILanguage());
475 if (pGetThreadUILanguage
)
476 xprintf (" ThreadUILanguage=%04x\n", pGetThreadUILanguage());
479 static inline BOOL
is_dot_dir(const char* x
)
481 return ((x
[0] == '.') && ((x
[1] == 0) || ((x
[1] == '.') && (x
[2] == 0))));
484 static void remove_dir (const char *dir
)
487 WIN32_FIND_DATAA wfd
;
489 size_t dirlen
= strlen (dir
);
491 /* Make sure the directory exists before going further */
492 memcpy (path
, dir
, dirlen
);
493 strcpy (path
+ dirlen
++, "\\*");
494 hFind
= FindFirstFileA (path
, &wfd
);
495 if (hFind
== INVALID_HANDLE_VALUE
) return;
498 char *lp
= wfd
.cFileName
;
500 if (!lp
[0]) lp
= wfd
.cAlternateFileName
; /* ? FIXME not (!lp) ? */
501 if (is_dot_dir (lp
)) continue;
502 strcpy (path
+ dirlen
, lp
);
503 if (FILE_ATTRIBUTE_DIRECTORY
& wfd
.dwFileAttributes
)
505 else if (!DeleteFileA(path
))
506 report (R_WARNING
, "Can't delete file %s: error %d",
507 path
, GetLastError ());
508 } while (FindNextFileA(hFind
, &wfd
));
510 if (!RemoveDirectoryA(dir
))
511 report (R_WARNING
, "Can't remove directory %s: error %d",
512 dir
, GetLastError ());
515 static const char* get_test_source_file(const char* test
, const char* subtest
)
517 static const char* special_dirs
[][2] = {
520 static char buffer
[MAX_PATH
];
521 int i
, len
= strlen(test
);
523 if (len
> 4 && !strcmp( test
+ len
- 4, ".exe" ))
525 len
= sprintf(buffer
, "programs/%s", test
) - 4;
528 else len
= sprintf(buffer
, "dlls/%s", test
);
530 for (i
= 0; special_dirs
[i
][0]; i
++) {
531 if (strcmp(test
, special_dirs
[i
][0]) == 0) {
532 strcpy( buffer
, special_dirs
[i
][1] );
533 len
= strlen(buffer
);
538 sprintf(buffer
+ len
, "/tests/%s.c", subtest
);
542 static void* extract_rcdata (LPCSTR name
, LPCSTR type
, DWORD
* size
)
548 if (!(rsrc
= FindResourceA(NULL
, name
, type
)) ||
549 !(*size
= SizeofResource (0, rsrc
)) ||
550 !(hdl
= LoadResource (0, rsrc
)) ||
551 !(addr
= LockResource (hdl
)))
556 /* Fills in the name and exename fields */
558 extract_test (struct wine_test
*test
, const char *dir
, LPSTR res_name
)
566 code
= extract_rcdata (res_name
, "TESTRES", &size
);
567 if (!code
) report (R_FATAL
, "Can't find test resource %s: %d",
568 res_name
, GetLastError ());
569 test
->name
= heap_strdup( res_name
);
570 test
->exename
= strmake (NULL
, "%s\\%s", dir
, test
->name
);
571 exepos
= strstr (test
->name
, testexe
);
572 if (!exepos
) report (R_FATAL
, "Not an .exe file: %s", test
->name
);
574 test
->name
= heap_realloc (test
->name
, exepos
- test
->name
+ 1);
575 report (R_STEP
, "Extracting: %s", test
->name
);
577 hfile
= CreateFileA(test
->exename
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
,
578 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
579 if (hfile
== INVALID_HANDLE_VALUE
)
580 report (R_FATAL
, "Failed to open file %s.", test
->exename
);
582 if (!WriteFile(hfile
, code
, size
, &written
, NULL
))
583 report (R_FATAL
, "Failed to write file %s.", test
->exename
);
588 static DWORD
wait_process( HANDLE process
, DWORD timeout
)
590 DWORD wait
, diff
= 0, start
= GetTickCount();
593 while (diff
< timeout
)
595 wait
= MsgWaitForMultipleObjects( 1, &process
, FALSE
, timeout
- diff
, QS_ALLINPUT
);
596 if (wait
!= WAIT_OBJECT_0
+ 1) return wait
;
597 while (PeekMessageA( &msg
, 0, 0, 0, PM_REMOVE
)) DispatchMessageA( &msg
);
598 diff
= GetTickCount() - start
;
603 static void append_path( const char *path
)
607 newpath
= heap_alloc(strlen(curpath
) + 1 + strlen(path
) + 1);
608 strcpy(newpath
, curpath
);
609 strcat(newpath
, ";");
610 strcat(newpath
, path
);
611 SetEnvironmentVariableA("PATH", newpath
);
616 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
619 Return the exit status, -2 if can't create process or the return
620 value of WaitForSingleObject.
623 run_ex (char *cmd
, HANDLE out_file
, const char *tempdir
, DWORD ms
)
626 PROCESS_INFORMATION pi
;
629 GetStartupInfoA (&si
);
630 si
.dwFlags
= STARTF_USESTDHANDLES
;
631 si
.hStdInput
= GetStdHandle( STD_INPUT_HANDLE
);
632 si
.hStdOutput
= out_file
? out_file
: GetStdHandle( STD_OUTPUT_HANDLE
);
633 si
.hStdError
= out_file
? out_file
: GetStdHandle( STD_ERROR_HANDLE
);
635 if (!CreateProcessA (NULL
, cmd
, NULL
, NULL
, TRUE
, CREATE_DEFAULT_ERROR_MODE
,
636 NULL
, tempdir
, &si
, &pi
))
639 CloseHandle (pi
.hThread
);
640 status
= wait_process( pi
.hProcess
, ms
);
644 GetExitCodeProcess (pi
.hProcess
, &status
);
645 CloseHandle (pi
.hProcess
);
648 report (R_ERROR
, "Wait for '%s' failed: %d", cmd
, GetLastError ());
653 report (R_ERROR
, "Wait returned %d", status
);
656 if (!TerminateProcess (pi
.hProcess
, 257))
657 report (R_ERROR
, "TerminateProcess failed: %d", GetLastError ());
658 wait
= wait_process( pi
.hProcess
, 5000 );
664 report (R_ERROR
, "Wait for termination of '%s' failed: %d", cmd
, GetLastError ());
667 report (R_ERROR
, "Can't kill process '%s'", cmd
);
670 report (R_ERROR
, "Waiting for termination: %d", wait
);
673 CloseHandle (pi
.hProcess
);
678 get_subtests (const char *tempdir
, struct wine_test
*test
, LPSTR res_name
)
683 char buffer
[8192], *index
;
684 static const char header
[] = "Valid test names:";
685 int status
, allocated
;
686 char tmpdir
[MAX_PATH
], subname
[MAX_PATH
];
687 SECURITY_ATTRIBUTES sa
;
689 test
->subtest_count
= 0;
691 if (!GetTempPathA( MAX_PATH
, tmpdir
) ||
692 !GetTempFileNameA( tmpdir
, "sub", 0, subname
))
693 report (R_FATAL
, "Can't name subtests file.");
695 /* make handle inheritable */
696 sa
.nLength
= sizeof(sa
);
697 sa
.lpSecurityDescriptor
= NULL
;
698 sa
.bInheritHandle
= TRUE
;
700 subfile
= CreateFileA( subname
, GENERIC_READ
|GENERIC_WRITE
,
701 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
702 &sa
, CREATE_ALWAYS
, 0, NULL
);
704 if ((subfile
== INVALID_HANDLE_VALUE
) &&
705 (GetLastError() == ERROR_INVALID_PARAMETER
)) {
706 /* FILE_SHARE_DELETE not supported on win9x */
707 subfile
= CreateFileA( subname
, GENERIC_READ
|GENERIC_WRITE
,
708 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
709 &sa
, CREATE_ALWAYS
, 0, NULL
);
711 if (subfile
== INVALID_HANDLE_VALUE
) {
712 err
= GetLastError();
713 report (R_ERROR
, "Can't open subtests output of %s: %u",
714 test
->name
, GetLastError());
718 cmd
= strmake (NULL
, "%s --list", test
->exename
);
719 if (test
->maindllpath
) {
720 /* We need to add the path (to the main dll) to PATH */
721 append_path(test
->maindllpath
);
723 status
= run_ex (cmd
, subfile
, tempdir
, 5000);
724 err
= GetLastError();
725 if (test
->maindllpath
) {
726 /* Restore PATH again */
727 SetEnvironmentVariableA("PATH", curpath
);
733 report (R_ERROR
, "Cannot run %s error %u", test
->exename
, err
);
734 CloseHandle( subfile
);
738 SetFilePointer( subfile
, 0, NULL
, FILE_BEGIN
);
739 ReadFile( subfile
, buffer
, sizeof(buffer
), &total
, NULL
);
740 CloseHandle( subfile
);
741 if (sizeof buffer
== total
) {
742 report (R_ERROR
, "Subtest list of %s too big.",
743 test
->name
, sizeof buffer
);
744 err
= ERROR_OUTOFMEMORY
;
749 index
= strstr (buffer
, header
);
751 report (R_ERROR
, "Can't parse subtests output of %s",
753 err
= ERROR_INTERNAL_ERROR
;
756 index
+= sizeof header
;
759 test
->subtests
= heap_alloc (allocated
* sizeof(char*));
760 index
= strtok (index
, whitespace
);
762 if (test
->subtest_count
== allocated
) {
764 test
->subtests
= heap_realloc (test
->subtests
,
765 allocated
* sizeof(char*));
767 test
->subtests
[test
->subtest_count
++] = heap_strdup(index
);
768 index
= strtok (NULL
, whitespace
);
770 test
->subtests
= heap_realloc (test
->subtests
,
771 test
->subtest_count
* sizeof(char*));
775 if (!DeleteFileA (subname
))
776 report (R_WARNING
, "Can't delete file '%s': %u", subname
, GetLastError());
781 run_test (struct wine_test
* test
, const char* subtest
, HANDLE out_file
, const char *tempdir
)
783 const char* file
= get_test_source_file(test
->name
, subtest
);
785 if (test_filtered_out( test
->name
, subtest
))
787 report (R_STEP
, "Skipping: %s:%s", test
->name
, subtest
);
788 xprintf ("%s:%s skipped %s -\n", test
->name
, subtest
, file
);
794 DWORD start
= GetTickCount();
795 char *cmd
= strmake (NULL
, "%s %s", test
->exename
, subtest
);
796 report (R_STEP
, "Running: %s:%s", test
->name
, subtest
);
797 xprintf ("%s:%s start %s -\n", test
->name
, subtest
, file
);
798 status
= run_ex (cmd
, out_file
, tempdir
, 120000);
800 xprintf ("%s:%s done (%d) in %ds\n", test
->name
, subtest
, status
, (GetTickCount()-start
)/1000);
801 if (status
) failures
++;
803 if (failures
) report (R_STATUS
, "Running tests - %u failures", failures
);
807 EnumTestFileProc (HMODULE hModule
, LPCSTR lpszType
,
808 LPSTR lpszName
, LONG_PTR lParam
)
810 if (!test_filtered_out( lpszName
, NULL
)) (*(int*)lParam
)++;
814 static const struct clsid_mapping
820 {"oledb32", {0xc8b522d1, 0x5cf3, 0x11ce, {0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d}}},
821 {NULL
, {0, 0, 0, {0,0,0,0,0,0,0,0}}}
825 static BOOL
get_main_clsid(const char *name
, CLSID
*clsid
)
827 const struct clsid_mapping
*mapping
;
829 for(mapping
= clsid_list
; mapping
->name
; mapping
++)
831 if(!strcasecmp(name
, mapping
->name
))
833 *clsid
= mapping
->clsid
;
840 static HMODULE
load_com_dll(const char *name
, char **path
, char *filename
)
845 char dllname
[MAX_PATH
];
849 if(!get_main_clsid(name
, &clsid
)) return NULL
;
851 sprintf(keyname
, "CLSID\\{%08x-%04x-%04x-%02x%2x-%02x%2x%02x%2x%02x%2x}\\InprocServer32",
852 clsid
.Data1
, clsid
.Data2
, clsid
.Data3
, clsid
.Data4
[0], clsid
.Data4
[1],
853 clsid
.Data4
[2], clsid
.Data4
[3], clsid
.Data4
[4], clsid
.Data4
[5],
854 clsid
.Data4
[6], clsid
.Data4
[7]);
856 if(RegOpenKeyA(HKEY_CLASSES_ROOT
, keyname
, &hkey
) == ERROR_SUCCESS
)
858 LONG size
= sizeof(dllname
);
859 if(RegQueryValueA(hkey
, NULL
, dllname
, &size
) == ERROR_SUCCESS
)
861 if ((dll
= LoadLibraryExA(dllname
, NULL
, LOAD_LIBRARY_AS_DATAFILE
)))
863 strcpy( filename
, dllname
);
864 p
= strrchr(dllname
, '\\');
866 *path
= heap_strdup( dllname
);
875 static void get_dll_path(HMODULE dll
, char **path
, char *filename
)
877 char dllpath
[MAX_PATH
];
879 GetModuleFileNameA(dll
, dllpath
, MAX_PATH
);
880 strcpy(filename
, dllpath
);
881 *strrchr(dllpath
, '\\') = '\0';
882 *path
= heap_strdup( dllpath
);
886 extract_test_proc (HMODULE hModule
, LPCSTR lpszType
, LPSTR lpszName
, LONG_PTR lParam
)
888 const char *tempdir
= (const char *)lParam
;
889 char dllname
[MAX_PATH
];
890 char filename
[MAX_PATH
];
891 WCHAR dllnameW
[MAX_PATH
];
897 if (aborting
) return TRUE
;
899 /* Check if the main dll is present on this system */
900 CharLowerA(lpszName
);
901 strcpy(dllname
, lpszName
);
902 *strstr(dllname
, testexe
) = 0;
904 if (test_filtered_out( lpszName
, NULL
))
907 xprintf (" %s=skipped\n", dllname
);
910 extract_test (&wine_tests
[nr_of_files
], tempdir
, lpszName
);
912 if (pCreateActCtxA
!= NULL
&& pActivateActCtx
!= NULL
&&
913 pDeactivateActCtx
!= NULL
&& pReleaseActCtx
!= NULL
)
916 memset(&actctxinfo
, 0, sizeof(ACTCTXA
));
917 actctxinfo
.cbSize
= sizeof(ACTCTXA
);
918 actctxinfo
.dwFlags
= ACTCTX_FLAG_RESOURCE_NAME_VALID
;
919 actctxinfo
.lpSource
= wine_tests
[nr_of_files
].exename
;
920 actctxinfo
.lpResourceName
= (LPSTR
)CREATEPROCESS_MANIFEST_RESOURCE_ID
;
921 actctx
= pCreateActCtxA(&actctxinfo
);
922 if (actctx
!= INVALID_HANDLE_VALUE
&&
923 ! pActivateActCtx(actctx
, &cookie
))
925 pReleaseActCtx(actctx
);
926 actctx
= INVALID_HANDLE_VALUE
;
928 } else actctx
= INVALID_HANDLE_VALUE
;
930 wine_tests
[nr_of_files
].maindllpath
= NULL
;
931 strcpy(filename
, dllname
);
932 dll
= LoadLibraryExA(dllname
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
934 if (!dll
) dll
= load_com_dll(dllname
, &wine_tests
[nr_of_files
].maindllpath
, filename
);
936 if (!dll
&& pLoadLibraryShim
)
938 MultiByteToWideChar(CP_ACP
, 0, dllname
, -1, dllnameW
, MAX_PATH
);
939 if (SUCCEEDED( pLoadLibraryShim(dllnameW
, NULL
, NULL
, &dll
) ) && dll
)
941 get_dll_path(dll
, &wine_tests
[nr_of_files
].maindllpath
, filename
);
943 dll
= LoadLibraryExA(filename
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
950 xprintf (" %s=dll is missing\n", dllname
);
951 if (actctx
!= INVALID_HANDLE_VALUE
)
953 pDeactivateActCtx(0, cookie
);
954 pReleaseActCtx(actctx
);
958 if(is_stub_dll(dllname
))
961 xprintf (" %s=dll is a stub\n", dllname
);
962 if (actctx
!= INVALID_HANDLE_VALUE
)
964 pDeactivateActCtx(0, cookie
);
965 pReleaseActCtx(actctx
);
969 if (is_native_dll(dll
))
972 xprintf (" %s=load error Configured as native\n", dllname
);
974 if (actctx
!= INVALID_HANDLE_VALUE
)
976 pDeactivateActCtx(0, cookie
);
977 pReleaseActCtx(actctx
);
983 if (!(err
= get_subtests( tempdir
, &wine_tests
[nr_of_files
], lpszName
)))
985 xprintf (" %s=%s\n", dllname
, get_file_version(filename
));
986 nr_of_tests
+= wine_tests
[nr_of_files
].subtest_count
;
991 xprintf (" %s=load error %u\n", dllname
, err
);
994 if (actctx
!= INVALID_HANDLE_VALUE
)
996 pDeactivateActCtx(0, cookie
);
997 pReleaseActCtx(actctx
);
1003 run_tests (char *logname
, char *outdir
)
1006 char *strres
, *eol
, *nextline
;
1008 SECURITY_ATTRIBUTES sa
;
1009 char tmppath
[MAX_PATH
], tempdir
[MAX_PATH
+4];
1013 /* Get the current PATH only once */
1014 needed
= GetEnvironmentVariableA("PATH", NULL
, 0);
1015 curpath
= heap_alloc(needed
);
1016 GetEnvironmentVariableA("PATH", curpath
, needed
);
1018 SetErrorMode (SEM_FAILCRITICALERRORS
| SEM_NOGPFAULTERRORBOX
);
1020 if (!GetTempPathA( MAX_PATH
, tmppath
))
1021 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
1024 static char tmpname
[MAX_PATH
];
1025 if (!GetTempFileNameA( tmppath
, "res", 0, tmpname
))
1026 report (R_FATAL
, "Can't name logfile.");
1029 report (R_OUT
, logname
);
1031 /* make handle inheritable */
1032 sa
.nLength
= sizeof(sa
);
1033 sa
.lpSecurityDescriptor
= NULL
;
1034 sa
.bInheritHandle
= TRUE
;
1036 logfile
= CreateFileA( logname
, GENERIC_READ
|GENERIC_WRITE
,
1037 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1038 &sa
, CREATE_ALWAYS
, 0, NULL
);
1040 if ((logfile
== INVALID_HANDLE_VALUE
) &&
1041 (GetLastError() == ERROR_INVALID_PARAMETER
)) {
1042 /* FILE_SHARE_DELETE not supported on win9x */
1043 logfile
= CreateFileA( logname
, GENERIC_READ
|GENERIC_WRITE
,
1044 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
1045 &sa
, CREATE_ALWAYS
, 0, NULL
);
1047 if (logfile
== INVALID_HANDLE_VALUE
)
1048 report (R_FATAL
, "Could not open logfile: %u", GetLastError());
1050 /* try stable path for ZoneAlarm */
1052 strcpy( tempdir
, tmppath
);
1053 strcat( tempdir
, "wct" );
1055 if (!CreateDirectoryA( tempdir
, NULL
))
1057 if (!GetTempFileNameA( tmppath
, "wct", 0, tempdir
))
1058 report (R_FATAL
, "Can't name temporary dir (check %%TEMP%%).");
1059 DeleteFileA( tempdir
);
1060 if (!CreateDirectoryA( tempdir
, NULL
))
1061 report (R_FATAL
, "Could not create directory: %s", tempdir
);
1065 strcpy( tempdir
, outdir
);
1067 report (R_DIR
, tempdir
);
1069 xprintf ("Version 4\n");
1070 xprintf ("Tests from build %s\n", build_id
[0] ? build_id
: "-" );
1071 xprintf ("Archive: -\n"); /* no longer used */
1072 xprintf ("Tag: %s\n", tag
);
1073 xprintf ("Build info:\n");
1074 strres
= extract_rcdata ("BUILD_INFO", "STRINGRES", &strsize
);
1076 eol
= memchr (strres
, '\n', strsize
);
1079 eol
= strres
+ strsize
;
1081 strsize
-= eol
- strres
+ 1;
1082 nextline
= strsize
?eol
+1:NULL
;
1083 if (eol
> strres
&& *(eol
-1) == '\r') eol
--;
1085 xprintf (" %.*s\n", eol
-strres
, strres
);
1088 xprintf ("Operating system version:\n");
1091 xprintf ("Dll info:\n" );
1093 report (R_STATUS
, "Counting tests");
1094 if (!EnumResourceNamesA (NULL
, "TESTRES", EnumTestFileProc
, (LPARAM
)&nr_of_files
))
1095 report (R_FATAL
, "Can't enumerate test files: %d",
1097 wine_tests
= heap_alloc (nr_of_files
* sizeof wine_tests
[0]);
1099 /* Do this only once during extraction (and version checking) */
1100 hmscoree
= LoadLibraryA("mscoree.dll");
1101 pLoadLibraryShim
= NULL
;
1103 pLoadLibraryShim
= (void *)GetProcAddress(hmscoree
, "LoadLibraryShim");
1104 kernel32
= GetModuleHandleA("kernel32.dll");
1105 pCreateActCtxA
= (void *)GetProcAddress(kernel32
, "CreateActCtxA");
1106 pActivateActCtx
= (void *)GetProcAddress(kernel32
, "ActivateActCtx");
1107 pDeactivateActCtx
= (void *)GetProcAddress(kernel32
, "DeactivateActCtx");
1108 pReleaseActCtx
= (void *)GetProcAddress(kernel32
, "ReleaseActCtx");
1110 report (R_STATUS
, "Extracting tests");
1111 report (R_PROGRESS
, 0, nr_of_files
);
1115 if (!EnumResourceNamesA (NULL
, "TESTRES", extract_test_proc
, (LPARAM
)tempdir
))
1116 report (R_FATAL
, "Can't enumerate test files: %d",
1119 FreeLibrary(hmscoree
);
1121 if (aborting
) return logname
;
1123 xprintf ("Test output:\n" );
1125 report (R_DELTA
, 0, "Extracting: Done");
1128 report( R_WARNING
, "Some dlls are configured as native, you won't be able to submit results." );
1130 report (R_STATUS
, "Running tests");
1131 report (R_PROGRESS
, 1, nr_of_tests
);
1132 for (i
= 0; i
< nr_of_files
; i
++) {
1133 struct wine_test
*test
= wine_tests
+ i
;
1136 if (aborting
) break;
1138 if (test
->maindllpath
) {
1139 /* We need to add the path (to the main dll) to PATH */
1140 append_path(test
->maindllpath
);
1143 for (j
= 0; j
< test
->subtest_count
; j
++) {
1144 if (aborting
) break;
1145 run_test (test
, test
->subtests
[j
], logfile
, tempdir
);
1148 if (test
->maindllpath
) {
1149 /* Restore PATH again */
1150 SetEnvironmentVariableA("PATH", curpath
);
1153 report (R_DELTA
, 0, "Running: Done");
1155 report (R_STATUS
, "Cleaning up - %u failures", failures
);
1156 CloseHandle( logfile
);
1159 remove_dir (tempdir
);
1160 heap_free(wine_tests
);
1166 static BOOL WINAPI
ctrl_handler(DWORD ctrl_type
)
1168 if (ctrl_type
== CTRL_C_EVENT
) {
1169 printf("Ignoring Ctrl-C, use Ctrl-Break if you really want to terminate\n");
1177 static BOOL CALLBACK
1178 extract_only_proc (HMODULE hModule
, LPCSTR lpszType
, LPSTR lpszName
, LONG_PTR lParam
)
1180 const char *target_dir
= (const char *)lParam
;
1181 char filename
[MAX_PATH
];
1183 if (test_filtered_out( lpszName
, NULL
)) return TRUE
;
1185 strcpy(filename
, lpszName
);
1186 CharLowerA(filename
);
1188 extract_test( &wine_tests
[nr_of_files
], target_dir
, filename
);
1193 static void extract_only (const char *target_dir
)
1197 report (R_DIR
, target_dir
);
1198 res
= CreateDirectoryA( target_dir
, NULL
);
1199 if (!res
&& GetLastError() != ERROR_ALREADY_EXISTS
)
1200 report (R_FATAL
, "Could not create directory: %s (%d)", target_dir
, GetLastError ());
1203 report (R_STATUS
, "Counting tests");
1204 if (!EnumResourceNamesA(NULL
, "TESTRES", EnumTestFileProc
, (LPARAM
)&nr_of_files
))
1205 report (R_FATAL
, "Can't enumerate test files: %d", GetLastError ());
1207 wine_tests
= heap_alloc (nr_of_files
* sizeof wine_tests
[0] );
1209 report (R_STATUS
, "Extracting tests");
1210 report (R_PROGRESS
, 0, nr_of_files
);
1212 if (!EnumResourceNamesA(NULL
, "TESTRES", extract_only_proc
, (LPARAM
)target_dir
))
1213 report (R_FATAL
, "Can't enumerate test files: %d", GetLastError ());
1215 report (R_DELTA
, 0, "Extracting: Done");
1222 "Usage: winetest [OPTION]... [TESTS]\n\n"
1223 " --help print this message and exit\n"
1224 " --version print the build version and exit\n"
1225 " -c console mode, no GUI\n"
1226 " -d DIR Use DIR as temp directory (default: %%TEMP%%\\wct)\n"
1227 " -e preserve the environment\n"
1228 " -h print this message and exit\n"
1229 " -i INFO an optional description of the test platform\n"
1230 " -m MAIL an email address to enable developers to contact you\n"
1231 " -n exclude the specified tests\n"
1232 " -p shutdown when the tests are done\n"
1233 " -q quiet mode, no output at all\n"
1234 " -o FILE put report into FILE, do not submit\n"
1235 " -s FILE submit FILE, do not run tests\n"
1236 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n"
1237 " -u URL include TestBot URL in the report\n"
1238 " -x DIR Extract tests to DIR (default: .\\wct) and exit\n");
1241 int main( int argc
, char *argv
[] )
1243 BOOL (WINAPI
*pIsWow64Process
)(HANDLE hProcess
, PBOOL Wow64Process
);
1244 char *logname
= NULL
, *outdir
= NULL
;
1245 const char *extract
= NULL
;
1246 const char *cp
, *submit
= NULL
;
1249 int interactive
= 1;
1252 if (!LoadStringA( 0, IDS_BUILD_ID
, build_id
, sizeof(build_id
) )) build_id
[0] = 0;
1254 pIsWow64Process
= (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"),"IsWow64Process");
1255 if (!pIsWow64Process
|| !pIsWow64Process( GetCurrentProcess(), &is_wow64
)) is_wow64
= FALSE
;
1257 for (i
= 1; i
< argc
&& argv
[i
]; i
++)
1259 if (!strcmp(argv
[i
], "--help")) {
1263 else if (!strcmp(argv
[i
], "--version")) {
1264 printf("%-12.12s\n", build_id
[0] ? build_id
: "unknown");
1267 else if ((argv
[i
][0] != '-' && argv
[i
][0] != '/') || argv
[i
][2]) {
1268 if (nb_filters
== sizeof(filters
)/sizeof(filters
[0]))
1270 report (R_ERROR
, "Too many test filters specified");
1273 filters
[nb_filters
++] = argv
[i
];
1275 else switch (argv
[i
][1]) {
1277 report (R_TEXTMODE
);
1288 if (!(description
= argv
[++i
]))
1295 if (!(email
= argv
[++i
]))
1302 exclude_tests
= TRUE
;
1312 if (!(submit
= argv
[++i
]))
1318 report (R_WARNING
, "ignoring tag for submission");
1322 if (!(logname
= argv
[++i
]))
1329 if (!(tag
= argv
[++i
]))
1334 if (strlen (tag
) > MAXTAGLEN
)
1335 report (R_FATAL
, "tag is too long (maximum %d characters)",
1337 cp
= findbadtagchar (tag
);
1339 report (R_ERROR
, "invalid char in tag: %c", *cp
);
1345 if (!(url
= argv
[++i
]))
1352 report (R_TEXTMODE
);
1353 if (!(extract
= argv
[++i
]))
1356 extract_only (extract
);
1362 report (R_ERROR
, "invalid option: -%c", argv
[i
][1]);
1367 if (!submit
&& !extract
) {
1368 int is_win9x
= (GetVersion() & 0x80000000) != 0;
1370 report (R_STATUS
, "Starting up");
1373 report (R_WARNING
, "Running on win9x is not supported. You won't be able to submit results.");
1375 if (!running_on_visible_desktop ())
1376 report (R_FATAL
, "Tests must be run on a visible desktop");
1378 if (running_under_wine())
1380 if (!check_mount_mgr())
1381 report (R_FATAL
, "Mount manager not running, most likely your WINEPREFIX wasn't created correctly.");
1383 if (!check_wow64_registry())
1384 report (R_FATAL
, "WoW64 keys missing, most likely your WINEPREFIX wasn't created correctly.");
1386 if (!check_display_driver())
1387 report (R_FATAL
, "Unable to create a window, the display driver is not working.");
1390 SetConsoleCtrlHandler(ctrl_handler
, TRUE
);
1394 SetEnvironmentVariableA( "WINETEST_PLATFORM", running_under_wine () ? "wine" : "windows" );
1395 SetEnvironmentVariableA( "WINETEST_DEBUG", "1" );
1396 SetEnvironmentVariableA( "WINETEST_INTERACTIVE", "0" );
1397 SetEnvironmentVariableA( "WINETEST_REPORT_SUCCESS", "0" );
1402 report (R_FATAL
, "Please specify a tag (-t option) if "
1403 "running noninteractive!");
1404 if (guiAskTag () == IDABORT
) exit (1);
1410 report (R_FATAL
, "Please specify an email address (-m option) to enable developers\n"
1411 " to contact you about your report if necessary.");
1412 if (guiAskEmail () == IDABORT
) exit (1);
1416 report( R_WARNING
, "You won't be able to submit results without a valid build id.\n"
1417 "To submit results, winetest needs to be built from a git checkout." );
1420 logname
= run_tests (NULL
, outdir
);
1422 DeleteFileA(logname
);
1425 if (failures
> FAILURES_LIMIT
)
1427 "%d tests failed, there's probably something broken with your setup.\n"
1428 "You need to address this before submitting results.", failures
);
1430 if (build_id
[0] && nr_of_skips
<= SKIP_LIMIT
&& failures
<= FAILURES_LIMIT
&&
1431 !nr_native_dlls
&& !is_win9x
&&
1432 report (R_ASK
, MB_YESNO
, "Do you want to submit the test results?") == IDYES
)
1433 if (!send_file (logname
) && !DeleteFileA(logname
))
1434 report (R_WARNING
, "Can't remove logfile: %u", GetLastError());
1435 } else run_tests (logname
, outdir
);
1436 report (R_STATUS
, "Finished - %u failures", failures
);
1441 TOKEN_PRIVILEGES npr
;
1443 /* enable the shutdown privilege for the current process */
1444 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES
, &hToken
))
1446 LookupPrivilegeValueA(0, "SeShutdownPrivilege", &npr
.Privileges
[0].Luid
);
1447 npr
.PrivilegeCount
= 1;
1448 npr
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
1449 AdjustTokenPrivileges(hToken
, FALSE
, &npr
, 0, 0, 0);
1450 CloseHandle(hToken
);
1452 ExitWindowsEx(EWX_SHUTDOWN
| EWX_POWEROFF
| EWX_FORCEIFHUNG
, SHTDN_REASON_MAJOR_OTHER
| SHTDN_REASON_MINOR_OTHER
);