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

2022/5/28 1:22:09

本文主要是介绍【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;

}



这篇关于【C#】调用cmd.exe并获取结果的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程