我编译的AutoIt脚本本身运行正常但是从C#调用时它会运行但是没有完成执行。我编译的C#代码:
Process myExe = new Process();
Environment.CurrentDirectory = Path.GetDirectoryName(exeDir); //exeDir is full path of the AutoIt executable directory
ProcessStartInfo StartInfo = new ProcessStartInfo("");
StartInfo.FileName = exeFile; //exeFile is full path of the executable itself
StartInfo.Verb = "runas";
myExe = Process.Start(StartInfo);
它在AutoIt代码中停止在EnvUpdate()
上,并最终在其他一些函数上停止。如果我手动运行可执行文件,则不会发生这种情况
我从C#开始运行此可执行文件的批处理文件。和CreateNoWindow
和UseShellExecute
的组合。也没有成功:1)以管理员身份运行C#编译的可执行文件。 2)使用StartInfo.CreateNoWindow
和StartInfo.UseShellExecute
的组合。 3)从批处理文件运行AutoIt可执行文件。 4)通过批处理文件从Perl文件运行AutoIt可执行文件。 5)从Windows计划任务运行AutoIt可执行文件。 6)在没有ProcessStartInfo
的情况下运行AutoIt可执行文件,使用以下任一方法:
myExe = Process.Start("cmd.exe", "/c start /wait " + exeFile);
要么
myExe = Process.Start(exeFile);
这里是一个示例C#类,用于使用.WaitForExit()
对已编译的AutoIt脚本(EXE文件)进行外部调用,这应该是您的问题:
using System.Configuration;
using System.Diagnostics;
namespace RegressionTesting.Common.ThirdParty
{
public class ClickAtBrowserPosition
{
public static void CallClickAtBrowserPosition(string currentBrowserWindowTitle, int xPosition, int yPosition)
{
var pathClickAtBrowserPosition = ConfigurationManager.AppSettings["pathClickAtBrowserPosition"];
var clickAtBrowserPositionExe = ConfigurationManager.AppSettings["clickAtBrowserPositionExe"];
var process = new Process();
var startInfo = new ProcessStartInfo
{
WindowStyle = ProcessWindowStyle.Hidden, // don't show the cmd.exe which calls the program
FileName = "cmd.exe",
Arguments = @" /C cd " +
$@"""{pathClickAtBrowserPosition}"" && {clickAtBrowserPositionExe} ""{currentBrowserWindowTitle}"" {xPosition} {yPosition}"
};
process.StartInfo = startInfo;
process.Start();
process.WaitForExit(); // wait to finish the execution
}
}
}
已编译的AutoIt脚本用于单击窗口的相对位置(在本例中为浏览器)。