winetest: Fix the printf format for the version numbers.
[wine.git] / programs / winetest / main.c
blobb56ba79cf96c2796eabae02233431946d95042a3
1 /*
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.
28 #include "config.h"
29 #include "wine/port.h"
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <assert.h>
34 #include <errno.h>
35 #ifdef HAVE_UNISTD_H
36 # include <unistd.h>
37 #endif
38 #include <windows.h>
40 #include "winetest.h"
41 #include "resource.h"
43 struct wine_test
45 char *name;
46 int resource;
47 int subtest_count;
48 char **subtests;
49 char *exename;
52 char *tag = NULL;
53 static struct wine_test *wine_tests;
54 static int nr_of_files, nr_of_tests;
55 static const char whitespace[] = " \t\r\n";
56 static const char testexe[] = "_test.exe";
57 static char build_id[64];
59 static char * get_file_version(char * file_name)
61 static char version[32];
62 DWORD size;
63 DWORD handle;
65 size = GetFileVersionInfoSizeA(file_name, &handle);
66 if (size) {
67 char * data = xmalloc(size);
68 if (data) {
69 if (GetFileVersionInfoA(file_name, handle, size, data)) {
70 static char backslash[] = "\\";
71 VS_FIXEDFILEINFO *pFixedVersionInfo;
72 UINT len;
73 if (VerQueryValueA(data, backslash, (LPVOID *)&pFixedVersionInfo, &len)) {
74 sprintf(version, "%d.%d.%d.%d",
75 pFixedVersionInfo->dwFileVersionMS >> 16,
76 pFixedVersionInfo->dwFileVersionMS & 0xffff,
77 pFixedVersionInfo->dwFileVersionLS >> 16,
78 pFixedVersionInfo->dwFileVersionLS & 0xffff);
79 } else
80 sprintf(version, "version not available");
81 } else
82 sprintf(version, "unknown");
83 free(data);
84 } else
85 sprintf(version, "failed");
86 } else
87 sprintf(version, "version not available");
89 return version;
92 static int running_under_wine (void)
94 HMODULE module = GetModuleHandleA("ntdll.dll");
96 if (!module) return 0;
97 return (GetProcAddress(module, "wine_server_call") != NULL);
100 static int running_on_visible_desktop (void)
102 HWND desktop;
103 HMODULE huser32 = GetModuleHandle("user32.dll");
104 FARPROC pGetProcessWindowStation = GetProcAddress(huser32, "GetProcessWindowStation");
105 FARPROC pGetUserObjectInformationA = GetProcAddress(huser32, "GetUserObjectInformationA");
107 desktop = GetDesktopWindow();
108 if (!GetWindowLongPtrW(desktop, GWLP_WNDPROC)) /* Win9x */
109 return IsWindowVisible(desktop);
111 if (pGetProcessWindowStation && pGetUserObjectInformationA)
113 DWORD len;
114 HWINSTA wstation;
115 USEROBJECTFLAGS uoflags;
117 wstation = (HWINSTA)pGetProcessWindowStation();
118 assert(pGetUserObjectInformationA(wstation, UOI_FLAGS, &uoflags, sizeof(uoflags), &len));
119 return (uoflags.dwFlags & WSF_VISIBLE) != 0;
121 return IsWindowVisible(desktop);
124 static void print_version (void)
126 OSVERSIONINFOEX ver;
127 BOOL ext;
128 int is_win2k3_r2;
129 const char *(*wine_get_build_id)(void);
131 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
132 if (!(ext = GetVersionEx ((OSVERSIONINFO *) &ver)))
134 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
135 if (!GetVersionEx ((OSVERSIONINFO *) &ver))
136 report (R_FATAL, "Can't get OS version.");
139 xprintf (" bRunningUnderWine=%d\n", running_under_wine ());
140 xprintf (" bRunningOnVisibleDesktop=%d\n", running_on_visible_desktop ());
141 xprintf (" dwMajorVersion=%u\n dwMinorVersion=%u\n"
142 " dwBuildNumber=%u\n PlatformId=%u\n szCSDVersion=%s\n",
143 ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber,
144 ver.dwPlatformId, ver.szCSDVersion);
146 wine_get_build_id = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "wine_get_build_id");
147 if (wine_get_build_id) xprintf( " WineBuild=%s\n", wine_get_build_id() );
149 is_win2k3_r2 = GetSystemMetrics(SM_SERVERR2);
150 if(is_win2k3_r2)
151 xprintf(" R2 build number=%d\n", is_win2k3_r2);
153 if (!ext) return;
155 xprintf (" wServicePackMajor=%d\n wServicePackMinor=%d\n"
156 " wSuiteMask=%d\n wProductType=%d\n wReserved=%d\n",
157 ver.wServicePackMajor, ver.wServicePackMinor, ver.wSuiteMask,
158 ver.wProductType, ver.wReserved);
161 static inline int is_dot_dir(const char* x)
163 return ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))));
166 static void remove_dir (const char *dir)
168 HANDLE hFind;
169 WIN32_FIND_DATA wfd;
170 char path[MAX_PATH];
171 size_t dirlen = strlen (dir);
173 /* Make sure the directory exists before going further */
174 memcpy (path, dir, dirlen);
175 strcpy (path + dirlen++, "\\*");
176 hFind = FindFirstFile (path, &wfd);
177 if (hFind == INVALID_HANDLE_VALUE) return;
179 do {
180 char *lp = wfd.cFileName;
182 if (!lp[0]) lp = wfd.cAlternateFileName; /* ? FIXME not (!lp) ? */
183 if (is_dot_dir (lp)) continue;
184 strcpy (path + dirlen, lp);
185 if (FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes)
186 remove_dir(path);
187 else if (!DeleteFile (path))
188 report (R_WARNING, "Can't delete file %s: error %d",
189 path, GetLastError ());
190 } while (FindNextFile (hFind, &wfd));
191 FindClose (hFind);
192 if (!RemoveDirectory (dir))
193 report (R_WARNING, "Can't remove directory %s: error %d",
194 dir, GetLastError ());
197 static const char* get_test_source_file(const char* test, const char* subtest)
199 static const char* special_dirs[][2] = {
200 { 0, 0 }
202 static char buffer[MAX_PATH];
203 int i;
205 for (i = 0; special_dirs[i][0]; i++) {
206 if (strcmp(test, special_dirs[i][0]) == 0) {
207 test = special_dirs[i][1];
208 break;
212 snprintf(buffer, sizeof(buffer), "dlls/%s/tests/%s.c", test, subtest);
213 return buffer;
216 static void* extract_rcdata (LPTSTR name, int type, DWORD* size)
218 HRSRC rsrc;
219 HGLOBAL hdl;
220 LPVOID addr;
222 if (!(rsrc = FindResource (NULL, name, MAKEINTRESOURCE(type))) ||
223 !(*size = SizeofResource (0, rsrc)) ||
224 !(hdl = LoadResource (0, rsrc)) ||
225 !(addr = LockResource (hdl)))
226 return NULL;
227 return addr;
230 /* Fills in the name and exename fields */
231 static void
232 extract_test (struct wine_test *test, const char *dir, LPTSTR res_name)
234 BYTE* code;
235 DWORD size;
236 char *exepos;
237 HANDLE hfile;
238 DWORD written;
240 code = extract_rcdata (res_name, TESTRES, &size);
241 if (!code) report (R_FATAL, "Can't find test resource %s: %d",
242 res_name, GetLastError ());
243 test->name = xstrdup( res_name );
244 test->exename = strmake (NULL, "%s\\%s", dir, test->name);
245 exepos = strstr (test->name, testexe);
246 if (!exepos) report (R_FATAL, "Not an .exe file: %s", test->name);
247 *exepos = 0;
248 test->name = xrealloc (test->name, exepos - test->name + 1);
249 report (R_STEP, "Extracting: %s", test->name);
251 hfile = CreateFileA(test->exename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
252 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
253 if (hfile == INVALID_HANDLE_VALUE)
254 report (R_FATAL, "Failed to open file %s.", test->exename);
256 if (!WriteFile(hfile, code, size, &written, NULL))
257 report (R_FATAL, "Failed to write file %s.", test->exename);
259 CloseHandle(hfile);
262 /* Run a command for MS milliseconds. If OUT != NULL, also redirect
263 stdout to there.
265 Return the exit status, -2 if can't create process or the return
266 value of WaitForSingleObject.
268 static int
269 run_ex (char *cmd, const char *out, const char *tempdir, DWORD ms)
271 STARTUPINFO si;
272 PROCESS_INFORMATION pi;
273 int fd, oldstdout = -1;
274 DWORD wait, status;
276 GetStartupInfo (&si);
277 si.dwFlags = 0;
279 if (out) {
280 fd = open (out, O_WRONLY | O_CREAT, 0666);
281 if (-1 == fd)
282 report (R_FATAL, "Can't open '%s': %d", out, errno);
283 oldstdout = dup (1);
284 if (-1 == oldstdout)
285 report (R_FATAL, "Can't save stdout: %d", errno);
286 if (-1 == dup2 (fd, 1))
287 report (R_FATAL, "Can't redirect stdout: %d", errno);
288 close (fd);
291 if (!CreateProcessA (NULL, cmd, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE,
292 NULL, tempdir, &si, &pi)) {
293 status = -2;
294 } else {
295 CloseHandle (pi.hThread);
296 wait = WaitForSingleObject (pi.hProcess, ms);
297 if (wait == WAIT_OBJECT_0) {
298 GetExitCodeProcess (pi.hProcess, &status);
299 } else {
300 switch (wait) {
301 case WAIT_FAILED:
302 report (R_ERROR, "Wait for '%s' failed: %d", cmd,
303 GetLastError ());
304 break;
305 case WAIT_TIMEOUT:
306 report (R_ERROR, "Process '%s' timed out.", cmd);
307 break;
308 default:
309 report (R_ERROR, "Wait returned %d", wait);
311 status = wait;
312 if (!TerminateProcess (pi.hProcess, 257))
313 report (R_ERROR, "TerminateProcess failed: %d",
314 GetLastError ());
315 wait = WaitForSingleObject (pi.hProcess, 5000);
316 switch (wait) {
317 case WAIT_FAILED:
318 report (R_ERROR,
319 "Wait for termination of '%s' failed: %d",
320 cmd, GetLastError ());
321 break;
322 case WAIT_OBJECT_0:
323 break;
324 case WAIT_TIMEOUT:
325 report (R_ERROR, "Can't kill process '%s'", cmd);
326 break;
327 default:
328 report (R_ERROR, "Waiting for termination: %d",
329 wait);
332 CloseHandle (pi.hProcess);
335 if (out) {
336 close (1);
337 if (-1 == dup2 (oldstdout, 1))
338 report (R_FATAL, "Can't recover stdout: %d", errno);
339 close (oldstdout);
341 return status;
344 static void
345 get_subtests (const char *tempdir, struct wine_test *test, LPTSTR res_name)
347 char *subname, *cmd;
348 FILE *subfile;
349 size_t total;
350 char buffer[8192], *index;
351 static const char header[] = "Valid test names:";
352 int allocated;
354 test->subtest_count = 0;
356 subname = tempnam (0, "sub");
357 if (!subname) report (R_FATAL, "Can't name subtests file.");
359 extract_test (test, tempdir, res_name);
360 cmd = strmake (NULL, "%s --list", test->exename);
361 run_ex (cmd, subname, tempdir, 5000);
362 free (cmd);
364 subfile = fopen (subname, "r");
365 if (!subfile) {
366 report (R_ERROR, "Can't open subtests output of %s: %d",
367 test->name, errno);
368 goto quit;
370 total = fread (buffer, 1, sizeof buffer, subfile);
371 fclose (subfile);
372 if (sizeof buffer == total) {
373 report (R_ERROR, "Subtest list of %s too big.",
374 test->name, sizeof buffer);
375 goto quit;
377 buffer[total] = 0;
379 index = strstr (buffer, header);
380 if (!index) {
381 report (R_ERROR, "Can't parse subtests output of %s",
382 test->name);
383 goto quit;
385 index += sizeof header;
387 allocated = 10;
388 test->subtests = xmalloc (allocated * sizeof(char*));
389 index = strtok (index, whitespace);
390 while (index) {
391 if (test->subtest_count == allocated) {
392 allocated *= 2;
393 test->subtests = xrealloc (test->subtests,
394 allocated * sizeof(char*));
396 test->subtests[test->subtest_count++] = strdup (index);
397 index = strtok (NULL, whitespace);
399 test->subtests = xrealloc (test->subtests,
400 test->subtest_count * sizeof(char*));
402 quit:
403 if (remove (subname))
404 report (R_WARNING, "Can't delete file '%s': %d",
405 subname, errno);
406 free (subname);
409 static void
410 run_test (struct wine_test* test, const char* subtest, const char *tempdir)
412 int status;
413 const char* file = get_test_source_file(test->name, subtest);
414 char *cmd = strmake (NULL, "%s %s", test->exename, subtest);
416 xprintf ("%s:%s start %s -\n", test->name, subtest, file);
417 status = run_ex (cmd, NULL, tempdir, 120000);
418 free (cmd);
419 xprintf ("%s:%s done (%d)\n", test->name, subtest, status);
422 static BOOL CALLBACK
423 EnumTestFileProc (HMODULE hModule, LPCTSTR lpszType,
424 LPTSTR lpszName, LONG_PTR lParam)
426 (*(int*)lParam)++;
427 return TRUE;
430 static BOOL CALLBACK
431 extract_test_proc (HMODULE hModule, LPCTSTR lpszType,
432 LPTSTR lpszName, LONG_PTR lParam)
434 const char *tempdir = (const char *)lParam;
435 char dllname[MAX_PATH];
436 HMODULE dll;
438 /* Check if the main dll is present on this system */
439 CharLowerA(lpszName);
440 strcpy(dllname, lpszName);
441 *strstr(dllname, testexe) = 0;
443 dll = LoadLibraryExA(dllname, NULL, LOAD_LIBRARY_AS_DATAFILE);
444 if (!dll) {
445 xprintf (" %s=dll is missing\n", dllname);
446 return TRUE;
448 FreeLibrary(dll);
450 xprintf (" %s=%s\n", dllname, get_file_version(dllname));
452 get_subtests( tempdir, &wine_tests[nr_of_files], lpszName );
453 nr_of_tests += wine_tests[nr_of_files].subtest_count;
454 nr_of_files++;
455 return TRUE;
458 static char *
459 run_tests (char *logname)
461 int i;
462 char *tempdir, *shorttempdir;
463 int logfile;
464 char *strres, *eol, *nextline;
465 DWORD strsize;
467 SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
469 if (!logname) {
470 logname = tempnam (0, "res");
471 if (!logname) report (R_FATAL, "Can't name logfile.");
473 report (R_OUT, logname);
475 logfile = open (logname, O_WRONLY | O_CREAT | O_EXCL | O_APPEND,
476 0666);
477 if (-1 == logfile) {
478 if (EEXIST == errno)
479 report (R_FATAL, "File %s already exists.", logname);
480 else report (R_FATAL, "Could not open logfile: %d", errno);
482 if (-1 == dup2 (logfile, 1))
483 report (R_FATAL, "Can't redirect stdout: %d", errno);
484 close (logfile);
486 tempdir = tempnam (0, "wct");
487 if (!tempdir)
488 report (R_FATAL, "Can't name temporary dir (check %%TEMP%%).");
489 shorttempdir = strdup (tempdir);
490 if (shorttempdir) { /* try stable path for ZoneAlarm */
491 strstr (shorttempdir, "wct")[3] = 0;
492 if (CreateDirectoryA (shorttempdir, NULL)) {
493 free (tempdir);
494 tempdir = shorttempdir;
495 } else free (shorttempdir);
497 if (tempdir != shorttempdir && !CreateDirectoryA (tempdir, NULL))
498 report (R_FATAL, "Could not create directory: %s", tempdir);
499 report (R_DIR, tempdir);
501 xprintf ("Version 4\n");
502 xprintf ("Tests from build %s\n", build_id[0] ? build_id : "-" );
503 strres = extract_rcdata (MAKEINTRESOURCE(TESTS_URL), STRINGRES, &strsize);
504 xprintf ("Archive: ");
505 if (strres) xprintf ("%.*s", strsize, strres);
506 else xprintf ("-\n");
507 xprintf ("Tag: %s\n", tag);
508 xprintf ("Build info:\n");
509 strres = extract_rcdata (MAKEINTRESOURCE(BUILD_INFO), STRINGRES, &strsize);
510 while (strres) {
511 eol = memchr (strres, '\n', strsize);
512 if (!eol) {
513 nextline = NULL;
514 eol = strres + strsize;
515 } else {
516 strsize -= eol - strres + 1;
517 nextline = strsize?eol+1:NULL;
518 if (eol > strres && *(eol-1) == '\r') eol--;
520 xprintf (" %.*s\n", eol-strres, strres);
521 strres = nextline;
523 xprintf ("Operating system version:\n");
524 print_version ();
525 xprintf ("Dll info:\n" );
527 report (R_STATUS, "Counting tests");
528 if (!EnumResourceNames (NULL, MAKEINTRESOURCE(TESTRES),
529 EnumTestFileProc, (LPARAM)&nr_of_files))
530 report (R_FATAL, "Can't enumerate test files: %d",
531 GetLastError ());
532 wine_tests = xmalloc (nr_of_files * sizeof wine_tests[0]);
534 report (R_STATUS, "Extracting tests");
535 report (R_PROGRESS, 0, nr_of_files);
536 nr_of_files = 0;
537 nr_of_tests = 0;
538 if (!EnumResourceNames (NULL, MAKEINTRESOURCE(TESTRES),
539 extract_test_proc, (LPARAM)tempdir))
540 report (R_FATAL, "Can't enumerate test files: %d",
541 GetLastError ());
543 xprintf ("Test output:\n" );
545 report (R_DELTA, 0, "Extracting: Done");
547 report (R_STATUS, "Running tests");
548 report (R_PROGRESS, 1, nr_of_tests);
549 for (i = 0; i < nr_of_files; i++) {
550 struct wine_test *test = wine_tests + i;
551 int j;
553 for (j = 0; j < test->subtest_count; j++) {
554 report (R_STEP, "Running: %s:%s", test->name,
555 test->subtests[j]);
556 run_test (test, test->subtests[j], tempdir);
559 report (R_DELTA, 0, "Running: Done");
561 report (R_STATUS, "Cleaning up");
562 close (1);
563 remove_dir (tempdir);
564 free (tempdir);
565 free (wine_tests);
567 return logname;
570 static void
571 usage (void)
573 fprintf (stderr,
574 "Usage: winetest [OPTION]...\n\n"
575 " -c console mode, no GUI\n"
576 " -e preserve the environment\n"
577 " -h print this message and exit\n"
578 " -p shutdown when the tests are done\n"
579 " -q quiet mode, no output at all\n"
580 " -o FILE put report into FILE, do not submit\n"
581 " -s FILE submit FILE, do not run tests\n"
582 " -t TAG include TAG of characters [-.0-9a-zA-Z] in the report\n");
585 int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst,
586 LPSTR cmdLine, int cmdShow)
588 char *logname = NULL;
589 const char *cp, *submit = NULL;
590 int reset_env = 1;
591 int poweroff = 0;
592 int interactive = 1;
594 if (!LoadStringA( 0, IDS_BUILD_ID, build_id, sizeof(build_id) )) build_id[0] = 0;
596 cmdLine = strtok (cmdLine, whitespace);
597 while (cmdLine) {
598 if (cmdLine[0] != '-' || cmdLine[2]) {
599 report (R_ERROR, "Not a single letter option: %s", cmdLine);
600 usage ();
601 exit (2);
603 switch (cmdLine[1]) {
604 case 'c':
605 report (R_TEXTMODE);
606 interactive = 0;
607 break;
608 case 'e':
609 reset_env = 0;
610 break;
611 case 'h':
612 case '?':
613 usage ();
614 exit (0);
615 case 'p':
616 poweroff = 1;
617 break;
618 case 'q':
619 report (R_QUIET);
620 interactive = 0;
621 break;
622 case 's':
623 submit = strtok (NULL, whitespace);
624 if (tag)
625 report (R_WARNING, "ignoring tag for submission");
626 send_file (submit);
627 break;
628 case 'o':
629 logname = strtok (NULL, whitespace);
630 break;
631 case 't':
632 tag = strtok (NULL, whitespace);
633 if (strlen (tag) > MAXTAGLEN)
634 report (R_FATAL, "tag is too long (maximum %d characters)",
635 MAXTAGLEN);
636 cp = findbadtagchar (tag);
637 if (cp) {
638 report (R_ERROR, "invalid char in tag: %c", *cp);
639 usage ();
640 exit (2);
642 break;
643 default:
644 report (R_ERROR, "invalid option: -%c", cmdLine[1]);
645 usage ();
646 exit (2);
648 cmdLine = strtok (NULL, whitespace);
650 if (!submit) {
651 static CHAR platform_windows[] = "WINETEST_PLATFORM=windows",
652 platform_wine[] = "WINETEST_PLATFORM=wine",
653 debug_yes[] = "WINETEST_DEBUG=1",
654 interactive_no[] = "WINETEST_INTERACTIVE=0",
655 report_success_no[] = "WINETEST_REPORT_SUCCESS=0";
656 CHAR *platform;
658 report (R_STATUS, "Starting up");
660 if (!running_on_visible_desktop ())
661 report (R_FATAL, "Tests must be run on a visible desktop");
663 platform = running_under_wine () ? platform_wine : platform_windows;
665 if (reset_env && (putenv (platform) ||
666 putenv (debug_yes) ||
667 putenv (interactive_no) ||
668 putenv (report_success_no)))
669 report (R_FATAL, "Could not reset environment: %d", errno);
671 if (!tag) {
672 if (!interactive)
673 report (R_FATAL, "Please specify a tag (-t option) if "
674 "running noninteractive!");
675 if (guiAskTag () == IDABORT) exit (1);
677 report (R_TAG);
679 if (!build_id[0])
680 report( R_WARNING, "You won't be able to submit results without a valid build id.\n"
681 "To submit results, winetest needs to be built from a git checkout." );
683 if (!logname) {
684 logname = run_tests (NULL);
685 if (build_id[0] &&
686 report (R_ASK, MB_YESNO, "Do you want to submit the test results?") == IDYES)
687 if (!send_file (logname) && remove (logname))
688 report (R_WARNING, "Can't remove logfile: %d.", errno);
689 free (logname);
690 } else run_tests (logname);
691 report (R_STATUS, "Finished");
693 if (poweroff)
695 HANDLE hToken;
696 TOKEN_PRIVILEGES npr;
698 /* enable the shutdown privilege for the current process */
699 if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
701 LookupPrivilegeValueA(0, SE_SHUTDOWN_NAME, &npr.Privileges[0].Luid);
702 npr.PrivilegeCount = 1;
703 npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
704 AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
705 CloseHandle(hToken);
707 ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);
709 exit (0);