How to Convert batch script to C# Windows Forms App

Rajat Sehgal
Rajat Sehgal used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
ste5anSenior Developer

Commented:
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#?
Rajat SehgalFounder Enhance Technology

Author

Commented:
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#.

Commented:
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

Bill PrewTest your restores, not your backups...
Top Expert 2016

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



»bp
Bill PrewTest your restores, not your backups...
Top Expert 2016
@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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial