批处理文件不通过Windows服务执行

时间:2012-07-18 11:53:17

标签: c# windows-services selenium-rc

我有一个场景,我必须创建一个Windows服务,它将检查如果批处理文件没有运行,那么它应该执行该批处理文件。

此外,我的批处理文件用于使用Selenium for Application checkout进行自动化。

当我创建该服务时,批处理文件不会以某种方式执行,也无法启动selenium。当我在任务管理器中看到相同内容时,我可以看到一个cmd实例正在运行,但是无法运行我的selenium。

我的项目代码:计时器设置为1分钟

private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
    if (!File.Exists(ConfigurationManager.AppSettings["testFilePath"])) //To check whether batch file is running or not 
    {
       System.Diagnostics.Process proc = new System.Diagnostics.Process(); // Declare New Process
        proc.StartInfo.FileName = ConfigurationManager.AppSettings["BatchFilePath"];
        proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
        proc.StartInfo.CreateNoWindow = true;
        proc.Start();
        proc.WaitForExit();
     }
}

批处理文件就像这样:

copy C:\AutomatedTests\AHD\testingWS.txt C:\AutomatedTests\AHD\AHDExecutionService\testingWS.txt

start cmd /k java -jar "C:\AHS_Automation\Release\UnifiedBillingSystem\Selenium RC\selenium-server-1.0.3\selenium-server.jar"

此代码将定期检查批处理文件是否未执行,然后我的服务将开始执行,否则将无效。

1 个答案:

答案 0 :(得分:1)

不确定这么少的上下文...但我要检查的第一件事是执行bat文件相对于bat文件使用的文件的路径;如果你从另一个程序调用bat文件,它通常会从该程序继承环境文件夹 - 这是大多数人不期望的。 (对于Windows服务,这是windows \ system32)检查是否是这种情况的最简单方法是在bat文件的第一行显式设置路径(例如cd [bat文件的路径])

相关问题