0

I have a scenario in which i have to create a windows service which will check that if the batch file is not running then it should execute that batch file.

Moreover, my batch file is used for automation using Selenium for Application checkout.

When i create that service, somehow the batch file is not executing and is not able to launch the selenium. When i see same in task manager, i can see a cmd instance is running but that cannot run my selenium.

Code of my Project: Timer is set to 1 minute

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();
     }
}

Batch File is like This:

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"

This code will check periodically that if batch file is not under execution then my service will start its execution otherwise will do nothing.

2
  • 1
    provide the code which is running the batch file. Commented Jul 18, 2012 at 12:06
  • @EstefanyVelez: I have updated the question with my code. Commented Jul 18, 2012 at 12:48

1 Answer 1

1

Not sure with so little context... but the first thing I would check is the path that executes the bat file with respect to the files that the bat file uses; if you're calling the bat file from another program, it normally inherits the environment folder from that program - which is something that most people don't expect. (for a windows service this is windows\system32) The easiest way to check if this is the case is by setting the path explicitly in the first line of the bat file (e.g. cd [path of bat file] )

Sign up to request clarification or add additional context in comments.

1 Comment

I have added the code for the windows service and also the batch file which needs to be executed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.