示例#1
0
def terminateRunningNVDA(window):
    processID, threadID = winUser.getWindowThreadProcessID(window)
    winUser.PostMessage(window, winUser.WM_QUIT, 0, 0)
    h = winKernel.openProcess(winKernel.SYNCHRONIZE, False, processID)
    if not h:
        # The process is already dead.
        return
    try:
        res = winKernel.waitForSingleObject(h, 4000)
        if res == 0:
            # The process terminated within the timeout period.
            return
    finally:
        winKernel.closeHandle(h)

    # The process is refusing to exit gracefully, so kill it forcefully.
    h = winKernel.openProcess(
        winKernel.PROCESS_TERMINATE | winKernel.SYNCHRONIZE, False, processID)
    if not h:
        raise OSError("Could not open process for termination")
    try:
        winKernel.TerminateProcess(h, 1)
        winKernel.waitForSingleObject(h, 2000)
    finally:
        winKernel.closeHandle(h)
示例#2
0
	def __init__(self,processID,appName=None):
		super(AppModule,self).__init__()
		#: The ID of the process this appModule is for.
		#: @type: int
		self.processID=processID
		if appName is None:
			appName=getAppNameFromProcessID(processID)
		#: The application name.
		#: @type: str
		self.appName=appName
		if winVersion.winVersion.major > 5:
			self.processHandle=winKernel.openProcess(winKernel.SYNCHRONIZE|winKernel.PROCESS_QUERY_INFORMATION,False,processID)
		else:
			self.processHandle=winKernel.openProcess(winKernel.SYNCHRONIZE|winKernel.PROCESS_QUERY_INFORMATION|winKernel.PROCESS_VM_READ,False,processID)
		self.helperLocalBindingHandle=None
		self._inprocRegistrationHandle=None
示例#3
0
    def __init__(self, processID, appName=None):
        super(AppModule, self).__init__()
        self.processID = processID
        if appName is None:
            appName = getAppNameFromProcessID(processID)
        self.appName = appName
        self.processHandle = winKernel.openProcess(
            winKernel.SYNCHRONIZE | winKernel.PROCESS_QUERY_INFORMATION, False,
            processID)
        self.helperLocalBindingHandle: Optional[ctypes.c_long] = None
        """RPC binding handle pointing to the RPC server for this process"""

        self._inprocRegistrationHandle = None
示例#4
0
文件: oleacc.py 项目: MarcoZehe/nvda
def GetProcessHandleFromHwnd(windowHandle):
	"""Retreaves a process handle of the process who owns the window.
	If Windows Vista, uses GetProcessHandleFromHwnd found in oleacc.dll which allows a client with UIAccess to open a process who is elevated.
	if older than Windows Vista, just uses OpenProcess from user32.dll instead.
	@param windowHandle: a window of a process you wish to retreave a process handle for
	@type windowHandle: integer
	@returns: a process handle with read, write and operation access
	@rtype: integer
	"""
	try:
		return oledll.oleacc.GetProcessHandleFromHwnd(windowHandle)
	except:
		import winKernel
		return winKernel.openProcess(winKernel.PROCESS_VM_READ|winKernel.PROCESS_VM_WRITE|winKernel.PROCESS_VM_OPERATION,False,winUser.getWindowThreadProcessID(windowHandle)[0])
示例#5
0
def GetProcessHandleFromHwnd(windowHandle):
	"""Retreaves a process handle of the process who owns the window.
	If Windows Vista, uses GetProcessHandleFromHwnd found in oleacc.dll which allows a client with UIAccess to open a process who is elevated.
	if older than Windows Vista, just uses OpenProcess from user32.dll instead.
	@param windowHandle: a window of a process you wish to retreave a process handle for
	@type windowHandle: integer
	@returns: a process handle with read, write and operation access
	@rtype: integer
	"""
	try:
		return oledll.oleacc.GetProcessHandleFromHwnd(windowHandle)
	except:
		import winKernel
		return winKernel.openProcess(winKernel.PROCESS_VM_READ|winKernel.PROCESS_VM_WRITE|winKernel.PROCESS_VM_OPERATION,False,winUser.getWindowThreadProcessID(windowHandle)[0])
示例#6
0
def getAppNameFromHost(processId):
	# Some apps that come with Windows 8 and 8.1 are hosted by wwahost.exe.
	# App modules for these are named after the hosted app name.
	processHandle = winKernel.openProcess(winKernel.SYNCHRONIZE|winKernel.PROCESS_QUERY_INFORMATION,False,processId)
	length = ctypes.c_uint()
	buf = winKernel.kernel32.GetApplicationUserModelId(processHandle, ctypes.byref(length), None)
	appModel = ctypes.create_unicode_buffer(buf)
	winKernel.kernel32.GetApplicationUserModelId(processHandle, ctypes.byref(length), appModel)
	winKernel.closeHandle(processHandle)
	# Sometimes app model might be empty, so raise errors and fall back to wwahost.
	if not appModel.value:
		raise LookupError
	# Convert this into lowercase to make the file name consistent with other NVDA app modules.
	return appModel.value.split("!")[-1].lower()
示例#7
0
def getAppNameFromHost(processId):
    # Some apps that come with Windows 8 and 8.1 are hosted by wwahost.exe.
    # App modules for these are named after the hosted app name.
    processHandle = winKernel.openProcess(
        winKernel.SYNCHRONIZE | winKernel.PROCESS_QUERY_INFORMATION, False,
        processId)
    length = ctypes.c_uint()
    buf = winKernel.kernel32.GetApplicationUserModelId(processHandle,
                                                       ctypes.byref(length),
                                                       None)
    appModel = ctypes.create_unicode_buffer(buf)
    winKernel.kernel32.GetApplicationUserModelId(processHandle,
                                                 ctypes.byref(length),
                                                 appModel)
    winKernel.closeHandle(processHandle)
    # Sometimes app model might be empty, so raise errors and fall back to wwahost.
    if not appModel.value:
        raise LookupError
    # Convert this into lowercase to make the file name consistent with other NVDA app modules.
    return appModel.value.split("!")[-1].lower()