1.新建一個bat文件
2.將cmd命令寫入bat文件中
例如:(功能是停止MySQL服務)
net stop MySQL
net start MySQL
c#代碼:
Process proc = new Process(); string targetDir = string.Format(@"D:\bat\"); proc.StartInfo.WorkingDirectory = targetDir; proc.StartInfo.FileName = "servicerestart.bat"; proc.StartInfo.Arguments = string.Format("10"); proc.Start(); proc.WaitForExit();