winetest: Add an option that shuts Windows down once the tests have completed.
Francois Gouget
fgouget at free.fr
Sat Oct 27 19:48:59 CDT 2007
---
This is quite useful in two circumstances:
* for someone starting the tests before going to bed. That way there's
no need to get up in the middle of the night just to turn the computer
off (though the tests don't take that long to run, yet).
* when running the tests in a virtual machine, the script outside the
virtual machine has no way to notice that the tests have finished
running. However detecting the shutdown of the virtual machine is easy.
So this lets my winetest script detect the tests completion instead of
systematically waiting for 30 minutes and hoping for the best.
Also, yes, you do need to specify EWX_SHUTDOWN | EWX_POWEROFF despite
what the MSDN tells you, in particular because Win9x does not know about
EWX_POWEROFF.
programs/winetest/Makefile.in | 2 +-
programs/winetest/main.c | 22 ++++++++++++++++++++++
2 files changed, 23 insertions(+), 1 deletions(-)
diff --git a/programs/winetest/Makefile.in b/programs/winetest/Makefile.in
index d640848..ad17524 100644
--- a/programs/winetest/Makefile.in
+++ b/programs/winetest/Makefile.in
@@ -4,7 +4,7 @@ SRCDIR = @srcdir@
VPATH = @srcdir@
MODULE = winetest.exe
APPMODE = -mconsole
-IMPORTS = comctl32 version user32 gdi32 wsock32 kernel32
+IMPORTS = advapi32 comctl32 version user32 gdi32 wsock32 kernel32
C_SRCS = \
gui.c \
diff --git a/programs/winetest/main.c b/programs/winetest/main.c
index 54574b1..41879b4 100644
--- a/programs/winetest/main.c
+++ b/programs/winetest/main.c
@@ -612,6 +612,7 @@ usage (void)
" -c console mode, no GUI\n"
" -e preserve the environment\n"
" -h print this message and exit\n"
+" -p shutdown when the tests are done\n"
" -q quiet mode, no output at all\n"
" -o FILE put report into FILE, do not submit\n"
" -s FILE submit FILE, do not run tests\n"
@@ -624,6 +625,7 @@ int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst,
char *logname = NULL;
const char *cp, *submit = NULL;
int reset_env = 1;
+ int poweroff = 0;
int interactive = 1;
/* initialize the revision information first */
@@ -645,8 +647,12 @@ int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst,
reset_env = 0;
break;
case 'h':
+ case '?':
usage ();
exit (0);
+ case 'p':
+ poweroff = 1;
+ break;
case 'q':
report (R_QUIET);
interactive = 0;
@@ -718,5 +724,21 @@ int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst,
} else run_tests (logname);
report (R_STATUS, "Finished");
}
+ if (poweroff)
+ {
+ HANDLE hToken;
+ TOKEN_PRIVILEGES npr;
+
+ /* enable the shutdown privilege for the current process */
+ if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
+ {
+ LookupPrivilegeValueA(0, SE_SHUTDOWN_NAME, &npr.Privileges[0].Luid);
+ npr.PrivilegeCount = 1;
+ npr.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
+ AdjustTokenPrivileges(hToken, FALSE, &npr, 0, 0, 0);
+ CloseHandle(hToken);
+ }
+ ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER);
+ }
exit (0);
}
--
1.5.3.4
More information about the wine-patches
mailing list