Link to home
Start Free TrialLog in
Avatar of Rajat Sehgal
Rajat SehgalFlag for India

asked on

How to Convert batch script to C# Windows Forms App

Hi Experts,

I've a batch script for pinging multipal ip's, now i want convert this batch script to C# Windows Forms App (.NET Framework) & run ping with start button.

Please Suggest ?
COLO.txt
COLOPINGLOOP.txt
Avatar of ste5an
ste5an
Flag of Germany image

Well, use the Ping class.

But I have to ask: Why? What problem try you to solve here? Or do you want to learn C#?
Avatar of Rajat Sehgal

ASKER

I want to learn how to convert OR use batch script to C#. I've maximum program which is in batch script now need to convert with C#.
If you want to execute batch script by C# program, you can use this code:
Process proc = null;
            try
            {
                string batchScriptDirectory = string.Format(@"YourDirectory");
                proc = new Process();
                proc.StartInfo.WorkingDirectory = batchScriptDirectory;
                proc.StartInfo.FileName = "YourBatchFileName.bat";
                proc.StartInfo.CreateNoWindow = false;
                proc.Start();
                proc.WaitForExit();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace.ToString());
            }

Open in new window

Avatar of Bill Prew
Bill Prew

Why create your own when there are free utils available that do this?



»bp
@Rajat Sehgal,

Are you all set with this now, or do you need more help?  If all set, could you please close it out now.  If you need help with the question close process take a look at:



»bp
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.