![]() |
|
[C#] Running cmd Commands via Application - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: Coding (https://sinister.ly/Forum-Coding--71) +--- Thread: [C#] Running cmd Commands via Application (/Thread-C-Running-cmd-Commands-via-Application) |
[C#] Running cmd Commands via Application - Travis - 06-08-2015 Hello there today I will show you how to run cmd commands such as /ipconfig in c# Let's get started ![]() Code: using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace cmd
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/ipconfig"; //Replace ipconfig with any command you may want :P
process.StartInfo = startInfo;
process.Start();
}
}
}RE: [C#] Running cmd Commands via Application - 3rd_Power - 06-09-2015 Very nice! However, this is why I like C++, you can replace all of the above code with a simple line: Code: system("ipconfig")RE: [C#] Running cmd Commands via Application - bitm0de - 07-29-2015 (06-09-2015, 05:11 PM)Prime02 Wrote: Very nice! However, this is why I like C++, you can replace all of the above code with a simple line: Nobody said you had to use the Process class in .NET (the VisualBasic dll contains Shell(): https://msdn.microsoft.com/en-us/library/xe736fyk%28v=vs.90%29.aspx), but the equivalent of Process.Start() in C++ is much more complex. Also, system() is not a good idea. |