[python-win32] Reboot apis don't work in a NT service

Tim Golden mail at timgolden.me.uk
Thu Mar 20 16:50:42 CET 2008

le dahut wrote:
> To reboot the computer I've tried this different functions :
> win32api.ExitWindowsEx(EWX_REBOOT | EWX_FORCE)
> win32api.InitiateSystemShutdown(None, '', 0, True, 1)
> win32ts.WTSShutdownSystem(wts.WTS_CURRENT_SERVER_HANDLE, wts.WTS_WSD_REBOOT)
> wa.WinExec('shutdown -r -t 0 -f')
> I've correctly setup 'SeShutdownPrivilege' before calling them.
> The "bForceAppsClosed" is set to True
> Since I noticed that they didn't reboot the computer but raised an 
> error, I've put them in a loop :
> while True:
>    try:
>      wa.ExitWindowsEx(...)
>      break
>    except Exception, e:
>      logging.error('%s'%e)
>      time.sleep(0.5)
> This permits to reboot the workstation after several minutes (between 3 
> and 9 minutes).

I'm not sure I can personally offer much here, le dahut, but
it would help if you showed the traceback you *are* getting.
Surely there's some clue in there which might suggest why
you're prevented from rebooting before a delay period.


More information about the python-win32 mailing list