C#的服务程序如何执行cmd或bat文件?如何执行dos命令

lwl0606 lwl0606 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
C#的windows服务程序如何执行cmd或bat文件,试了各种方法都不行;

System.Diagnostics.Process.Start(@"D:\Start_VM.bat");

这种不行;
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = "/c " + command;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = false;
p.Start();
outputMsg = p.StandardOutput.ReadToEnd();
p.Close();
这样也不行;

在应用程序中可以,但是到windows服务程序中就不可用了
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
lwl0606
C# 111,128 成员 642,537 内容