【问题标题】:How to restart explorer.exe process using Sikuli (Jython)?如何使用 Sikuli (Jython) 重启 explorer.exe 进程?
【发布时间】:2016-07-13 10:51:59
【问题描述】:

任务:我需要使用 Sikuli 重新启动 explorer.exe 进程。

我的解决方案是创建批处理文件“RestartExplorerProcess.bat”:

@echo off
echo Your desktop is being restored, Please wait. . .
ping -n 5 127.0.0.1 > NUL 2>&1
echo Killing process Explorer.exe. . .
taskkill /f /im explorer.exe
cls
echo Explorer.exe is killed!
echo.
echo Your desktop is now loading. . .
ping -n 5 127.0.0.1 > NUL 2>&1
echo.
ping -n 5 127.0.0.1 > NUL 2>&1
start %windir%\explorer.exe
echo Explorer.exe was successfully started!
exit

然后我使用:

subprocess.Popen(Path)

问题是我需要等待重启 explorer.exe 结束才能采取进一步的行动。 我为此找到了 3 个解决方案:

1. p = subprocess.Popen(Path)
   p.wait()
2. subprocess.check_call(Path)
3. os.system(Path)

但它们都具有相同的效果 - Sikuli 没有显示任何错误,只是挂起。也许我错了,但看起来在重新启动 explorer.exe 进程时我失去了一些参考,并且关于完成批处理文件的事件永远无法执行。

所以我的问题是:

  1. 如何使用常用的 Sikuli (Jython) 方法重新启动 explorer.exe 进程?
  2. 我如何才能等待使用上述任何方法完成我的批处理文件?

【问题讨论】:

  • 是什么导致了挂起? Popen 还是 p.wait()?如果是p.wait(),则使用默认的wait() 函数并指定一个大于启动explorer.exe 所需时间的超时。只需在 explorer.exe 重新启动时使用唯一的图像。

标签: windows batch-file jython explorer sikuli


【解决方案1】:

要使用 Sikuli 启动/重新启动 Firefox(或 Internet Explorer),我使用以下命令:

# Path to Firefox executable: 
PathFirefox = r"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
# Open Firefox 
App.open(PathFirefox)

要检查应用程序是否处于活动状态,您可以编写一个定义来检查应用程序是否处于活动状态。
例如:

def appActive(appName):
    call = 'TASKLIST', '/FI', 'imagename eq %s' % appName
    # Get the tasklist result
    proc = subprocess.Popen(call, shell=True, stdout=subprocess.PIPE)
    # Trimming lines with information
    output = proc.communicate()[0].strip().split('\r\n')
    # If TASKLIST returns multiple lines, it is running. 
    if len(output) > 1 and appName in output[-1]:
        print('Result: "%s" is running!' % appName)
        return True
    else:
        print('Result: "%s" is NOT running!' % appName)
        return False

# Check if Eclipse and Firefox are running: 
appActive('eclipse.exe')
appActive('firefox.exe')

【讨论】:

    【解决方案2】:

    您可以创建 2 支球棒:1 支用于击杀,另一支用于重新启动。之后,您可以检查是否存在桌面图像,这是一个功能。

    def restarExplorer():
        desktop_home = "your/file/location/desktop_home.png"
        killExplorer = App("your/file/location/killExplorer.exe")
        restartExplorer = App("your/file/location/restartExplorer.exe")
        killExplorer.open()
        sleep(3) # waiting 3 
        restartExplorer.open()
        while not exists(desktop_home): # check if desktop button appears
            sleep(1) # keep waiting
        continue..
    

    【讨论】:

      猜你喜欢
      • 2019-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多