OT (slightly): ExitWindowsEx issue

Windows 2000 / 98: I'm trying to use the win32api.ExitWindowsEx()
function to restart a Windows system. The documentation is minimal to
say the least. The function requires two parameters: flags, and
reserved=0 (according to the docs).

Actually, the docs specifically state that you should NOT use "0" for the
second parameter. However, it also says the parameter is ignored outside
of Windows Server 2003, so it shouldn't matter.

I'm not sure what the parameter options are.

MSDN is your friend. Did you Google for the API?

I took a guess and tried win32api.ExitWindowsEx(2, 0),
hoping that the system would shut down and restart.

Good guess: 2 is EWX_REBOOT.

As far as the
documentation goes, I'd say there's a good chance that these options
will shut down and restart the system. The documentation also says that
the command will check for open programs and give you the option to
close them. Now, when I run the script (Python 2.2.3) a dialog comes up
and says that 'python' is running (ok, pretty obvious) and gives me the
option to quit the app or cancel. The problem with this is that I would
like the script's execution to be scheduled and thus must not prompt for
user input (and obviously I don't want to exit the python interpreter
while it's running my script!).

Of course you do. You don't really expect your Python script to survive a
restart, do you? If the system is going to reboot anyway, why do you want
your script to keep running? Call ExitWindowsEx and then exit your
script.

I see at least three ways to solve this problem.

1) Pass the correct parameters to the ExitWindowsEx function.

You have the correct parameters.

#define EWX_LOGOFF 0
#define EWX_SHUTDOWN 0x00000001
#define EWX_REBOOT 0x00000002
#define EWX_FORCE 0x00000004
#define EWX_POWEROFF 0x00000008
#define EWX_FORCEIFHUNG 0x00000010
#define ExitWindows(dwReserved, Code) ExitWindowsEx(EWX_LOGOFF,
0xFFFFFFFF)

2) Use a completely different module or another win32api function to
restart the machine.

No, that's the one to use.

3) Maybe there's a different way to send a restart command to Windows
which doesn't care whether there are any open programs or not.

You can't be serious with this suggestion. Microsoft would be loony to
include such a feature. The first time you restarted while an app was in
the middle of a file write and ended up with the document being destroyed,
you'd be sued.

ยทยทยท

On Thu, 06 Nov 2003 19:32:22 +0200 Wayne Koorts <wayne@cwazy.co.uk> wrote:
--
- Tim Roberts, timr@probo.com
  Providenza & Boekelheide, Inc.