编程语言
首页 > 编程语言> > 【C#】调用cmd.exe并获取结果

【C#】调用cmd.exe并获取结果

作者:互联网

 

using (Process process = new Process())
{
string inputScriptPath = officeBits == "32bit" ? $@"cd c:\Program Files (x86)\Microsoft Office\{officeVer}\" : $@"cd c:\Program Files\Microsoft Office\{officeVer}\";
process.StartInfo.FileName = @"cmd.exe";
process.StartInfo.WorkingDirectory = @"C:\Windows\System32\";
process.StartInfo.Verb = "runas";
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.Start();
process.StandardInput.WriteLine(inputScriptPath);
process.StandardInput.WriteLine("cscript ospp.vbs /dstatus");
process.StandardInput.WriteLine("exit");
process.StandardInput.AutoFlush = true;
string output = process.StandardOutput.ReadToEnd();
process.Close();
return output;

}

标签:exe,C#,cmd,officeVer,process,StandardInput,WriteLine,StartInfo,true
来源: https://www.cnblogs.com/yzhyingcool/p/16319014.html