使用 AutoIt 启动相机应用程序 (Windows 10)

Launch camera application (Windows 10) using AutoIt

我正在尝试使用 ShellExecuteWait() 启动我的相机应用程序 (Windows 10)(因为我希望我的脚本等到我关闭相机应用程序)。但我似乎无法让它发挥作用。我尝试了帮助文件中的以下代码:

#include <MsgBoxConstants.au3>

Camera()

Func Camera()
   ;Execute Camera and wait for Camera to close
   Local $iReturn = ShellExecuteWait("notepad.exe")

   ;Display the return value
   MsgBox($MB_SYSTEMMODAL, "", "The return code from Notepad was: " & $iReturn)

EndFunc

这会显示记事本。当您关闭它时,会出现一个带有 return 值的消息框。但是,当我将 notepad.exe 更改为 explorer.exe 时,ShellExecuteWait() 似乎失败了(消息框立即出现)。

您无法使用 Run("camera.exe") 在 Windows 10 上打开相机;与 explorer.exe 一样,此操作失败并立即出现消息框。

这是我想要使用的代码:

#include <MsgBoxConstants.au3>

Camera()

Func Camera()
   ;Execute Camera and wait for Camera to close
   Local $iReturn = ShellExecuteWait("explorer.exe", "shell:AppsFolder\Microsoft.WindowsCamera_8wekyb3d8bbwe!App")

   ;Display the return value
   MsgBox($MB_SYSTEMMODAL, "", "The return code from Notepad was: " & $iReturn)

EndFunc 

ShellExecuteWait() 可能无法像 explorer 这样的服务器式进程按预期工作。 explorer.exe 总是 运行。对它的另一个调用只会告诉已经 运行 explorer.exe 显示额外的 window (就像许多浏览器不会创建其自身的另一个实例而只是一个新选项卡)。您可以使用 ProcessExplorer(来自 Sysinternals Suite)等工具检查当前进程层次结构。在那里你可以看到,那个记事本实际上是你的 autoit 脚本的一个子进程,其中 explorer.exesvhost.exe.

的子进程

您仍然可以尝试这样的操作:

#include <MsgBoxConstants.au3>

Camera()

Func Camera()
   ;Execute Camera and wait for Camera to close
   local $iPID = ShellExecuteWait("explorer.exe", "shell:AppsFolder\Microsoft.WindowsCamera_8wekyb3d8bbwe!App")
   Sleep(3000)
   WinWaitClose("Camera")

   ;Display the return value
   MsgBox($MB_SYSTEMMODAL, "", "The Camera was closed." )

EndFunc

这样,您的脚本将一直等待,直到不再存在名为 "Camera" 的 windows。请注意,结果将取决于 OS 语言(例如,对我来说是 "Kamera")。您可以使用工具 AutoIt Window Info 来查找与语言无关的特征。