~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/win32utils.py

  • Committer: Andrew Bennetts
  • Date: 2010-10-13 00:26:41 UTC
  • mto: This revision was merged to the branch mainline in revision 5498.
  • Revision ID: andrew.bennetts@canonical.com-20101013002641-9tlh9k89mlj1666m
Keep docs-plain working.

Show diffs side-by-side

added added

removed removed

Lines of Context:
468
468
 
469
469
 
470
470
def get_app_path(appname):
471
 
    r"""Look up in Windows registry for full path to application executable.
 
471
    """Look up in Windows registry for full path to application executable.
472
472
    Typically, applications create subkey with their basename
473
473
    in HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\
474
474
 
576
576
        return argv
577
577
else:
578
578
    get_unicode_argv = None
579
 
 
580
 
 
581
 
if has_win32api:
582
 
    def _pywin32_is_local_pid_dead(pid):
583
 
        """True if pid doesn't correspond to live process on this machine"""
584
 
        try:
585
 
            handle = win32api.OpenProcess(1, False, pid) # PROCESS_TERMINATE
586
 
        except pywintypes.error, e:
587
 
            if e[0] == 5: # ERROR_ACCESS_DENIED
588
 
                # Probably something alive we're not allowed to kill
589
 
                return False
590
 
            elif e[0] == 87: # ERROR_INVALID_PARAMETER
591
 
                return True
592
 
            raise
593
 
        handle.close()
594
 
        return False
595
 
    is_local_pid_dead = _pywin32_is_local_pid_dead
596
 
elif has_ctypes and sys.platform == 'win32':
597
 
    from ctypes.wintypes import BOOL, DWORD, HANDLE
598
 
    _kernel32 = ctypes.windll.kernel32
599
 
    _CloseHandle = ctypes.WINFUNCTYPE(BOOL, HANDLE)(
600
 
        ("CloseHandle", _kernel32))
601
 
    _OpenProcess = ctypes.WINFUNCTYPE(HANDLE, DWORD, BOOL, DWORD)(
602
 
        ("OpenProcess", _kernel32))
603
 
    def _ctypes_is_local_pid_dead(pid):
604
 
        """True if pid doesn't correspond to live process on this machine"""
605
 
        handle = _OpenProcess(1, False, pid) # PROCESS_TERMINATE
606
 
        if not handle:
607
 
            errorcode = ctypes.GetLastError()
608
 
            if errorcode == 5: # ERROR_ACCESS_DENIED
609
 
                # Probably something alive we're not allowed to kill
610
 
                return False
611
 
            elif errorcode == 87: # ERROR_INVALID_PARAMETER
612
 
                return True
613
 
            raise ctypes.WinError(errorcode)
614
 
        _CloseHandle(handle)
615
 
        return False
616
 
    is_local_pid_dead = _ctypes_is_local_pid_dead