雙擊即可套用 IP 設定:
@echo Anytao is switching your ip now.
@echo off
netsh interface ip set address "區域連線" static 172.1.1.226 255.0.0.0 172.30.7.254 1
netsh interface ip set dns "區域連線" static 200.121.5.1
echo ...www.anytao.com...
Echo Congratulations, done.
pause
System.Diagnostics.Process 提供存取本機進程、啟動/停止應用程式、取得模組與效能資訊等功能,是托管環境下啟動外部程式的推薦方式。


private void btnIpconfig_Click(object sender, EventArgs e)
{
try
{
Process myProcess = new Process();
myProcess.StartInfo.FileName = Application.StartupPath + @"\config\" + cbbIP.SelectedItem.ToString() + ".bat";
MessageBox.Show(myProcess.StartInfo.FileName);
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.Start();
myProcess.WaitForExit();
}
catch (FileNotFoundException ex)
{
MessageBox.Show(ex.Message);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
關鍵:UseShellExecute=false 才能重導向輸出;WaitForExit() 確保批次完成才繼續。