Пример #1
0
def beNice(very_nice=False):
    if RUNNING_WINDOWS:
        if very_nice:
            value = BELOW_NORMAL_PRIORITY_CLASS
        else:
            value = IDLE_PRIORITY_CLASS

        pid = GetCurrentProcessId()
        handle = OpenProcess(PROCESS_ALL_ACCESS, True, pid)
        SetPriorityClass(handle, value)
    else:
        if very_nice:
            value = 10
        else:
            value = 5
        nice(value)
Пример #2
0
 def beNice():
     process = GetCurrentProcess()
     # FIXME: Not supported on Windows 95/98/Me/NT: ignore error?
     # which error?
     SetPriorityClass(process, BELOW_NORMAL_PRIORITY_CLASS)
Пример #3
0
    def __call__(
        self,
        pathname='',
        arguments='',
        winState=0,
        waitForCompletion=False,
        priority=2,
        workingDir="",
        triggerEvent=False,
        disableWOW64=False,
        additionalSuffix="",
        disableParsingPathname=False,
        disableParsingArguments=False,
        disableParsingAdditionalSuffix=False,
        runAsAdmin=False,
    ):
        if eg.config.refreshEnv:
            eg.Environment.Refresh()
        returnValue = None
        pathname = expandvars(pathname)
        arguments = expandvars(arguments)
        workingDir = expandvars(workingDir)
        if not disableParsingPathname:
            pathname = eg.ParseString(pathname)
        if not disableParsingArguments:
            arguments = eg.ParseString(arguments)
        if not disableParsingAdditionalSuffix:
            additionalSuffix = eg.ParseString(additionalSuffix)
        if not workingDir:
            workingDir = dirname(abspath(pathname))
        processInformation = self.processInformation = SHELLEXECUTEINFO()
        processInformation.cbSize = sizeof(processInformation)
        processInformation.hwnd = 0
        processInformation.lpFile = pathname
        processInformation.lpParameters = arguments
        processInformation.lpDirectory = workingDir
        processInformation.nShow = WINSTATE_FLAGS[winState]
        processInformation.hInstApp = 0
        processInformation.fMask = SEE_MASK_NOCLOSEPROCESS
        if runAsAdmin:
            processInformation.lpVerb = "runas"
        disableWOW64 = disableWOW64 and IsWin64()
        if disableWOW64:
            prevVal = Wow64DisableWow64FsRedirection()
        activeThread = GetWindowThreadProcessId(GetForegroundWindow(), None)
        currentThread = GetCurrentThreadId()
        attached = AttachThreadInput(currentThread, activeThread, True)

        if not windll.shell32.ShellExecuteExW(byref(processInformation)):
            raise self.Exception(FormatError())

        if attached:
            AttachThreadInput(currentThread, activeThread, False)
        if disableWOW64:
            Wow64RevertWow64FsRedirection(prevVal)
        if priority != 2:
            try:
                SetPriorityClass(processInformation.hProcess,
                                 PRIORITY_FLAGS[priority])
                priorityClass = GetPriorityClass(processInformation.hProcess)
                if priorityClass != PRIORITY_FLAGS[priority]:
                    raise
            except:
                pid = windll.kernel32.GetProcessId(processInformation.hProcess)
                pi = SHELLEXECUTEINFO()
                pi.cbSize = sizeof(pi)
                pi.lpFile = r"C:\Windows\System32\wbem\wmic.exe"
                pi.lpParameters = (
                    "process where processid=%d CALL setpriority %d" %
                    (pid, PRIORITY_FLAGS[priority]))
                pi.lpVerb = "runas"
                if not windll.shell32.ShellExecuteExW(byref(pi)):
                    eg.PrintError(self.text.priorityIssue)
        suffix = "%s.%s" % (self.text.eventSuffix, splitext(
            split(pathname)[1])[0])
        if additionalSuffix != "":
            suffix = suffix + "." + additionalSuffix
        prefix = self.plugin.name.replace(' ', '')
        if waitForCompletion:
            WaitForSingleObject(processInformation.hProcess, INFINITE)
            exitCode = DWORD()
            if not GetExitCodeProcess(processInformation.hProcess,
                                      byref(exitCode)):
                raise self.Exception(FormatError())
            returnValue = exitCode.value
            if triggerEvent:
                eg.TriggerEvent(suffix, prefix=prefix)
            CloseHandle(processInformation.hProcess)
            return returnValue
        elif triggerEvent:
            te = self.TriggerEvent(processInformation, suffix, prefix)
            te.start()
        else:
            CloseHandle(processInformation.hProcess)