Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After opening process start command prompt how to write ipconfig in c#

I am opening the command prompt from c#

 Process.Start("cmd");

when it opens i need to write ipconfig automatically such that process opens and finds the ip of the workstation, How should i do that?

like image 433
Sohail Avatar asked Jan 20 '26 07:01

Sohail


2 Answers

EDIT

Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "ipconfig.exe";
p.Start();
p.WaitForExit();
string output = p.StandardOutput.ReadToEnd();
return output;

or

EDIT

  Process pr = new Process();
  pr.StartInfo.FileName = "cmd.exe";
  pr.StartInfo.Arguments = "/k ipconfig"; 
  pr.Start();

Check : How to Execute a Command in C# ?

System.Diagnostics.Process process = new System.Diagnostics.Process(); 
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
 startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
 startInfo.FileName = "cmd.exe";
 startInfo.Arguments = "ipconfig";
 process.StartInfo = startInfo;
 process.Start(); 

or

like image 140
Pranay Rana Avatar answered Jan 22 '26 20:01

Pranay Rana


Try this

 string strCmdText; 
 strCmdText= "ipconfig";
 System.Diagnostics.Process.Start("CMD.exe",strCmdText);
like image 44
Ali Hasan Avatar answered Jan 22 '26 22:01

Ali Hasan