ShellExecuteEx action returns invalid hProcess??

Posted by kurtball on 2014-11-04 09:44

I'm attempting to do this this:

import sys
import win32com.shell.shell as shell
import win32event

result=shell.ShellExecuteEx(lpVerb='runas',lpFile=sys.executable,lpParameters=sys.argv)
win32event.WaitForSingleObject(result['hProcess'],1000)

But it tells me,

...
  File "elevate.py", line 47, in _elevate
    win32event.WaitForSingleObject(result['hProcess'],1000)
pywintypes.error: (6, 'WaitForSingleObject', 'The handle is invalid.')

I'm confused. BTW, result['hProcess'] looks like a reasonable handle when I print it out.