繁体   English   中英

从 C# 运行 exe

[英]Run an exe from C#

我在从 C# 代码调用 PsService 时遇到问题。 当我从 cmd 写psservice \\\\ip -u user -p Calendar# restart spooler (init.txt) 时,它没问题,但在 C# 中我遇到了问题。 我的代码:

System.Diagnostics.Process process = new System.Diagnostics.Process();
            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
            startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            startInfo.UseShellExecute = false;
            startInfo.FileName = @"C:\exe\PsService";
            startInfo.Arguments = @"C:\exe\init.txt";
            process.StartInfo = startInfo;
            process.Start();

然后我从 cmd 运行 bin\\debug\\myExe 但写了这个:

如果您的帐户无权执行您指定的操作,请使用用户名和密码登录远程计算机。

如果您知道 cmd 代码运行良好,那么最简单的方法是通过 cmd 调用您的任何 exe 应用程序。 不要陷入混乱。

Process.start("cmd.exe","/c [enter cmd code]")

替换[enter cmd code]不带方括号 [ ]

我犯了一个愚蠢的错误:)

   startInfo.FileName = @"C:\exe\PsService";
   startInfo.Arguments = @"C:\exe\init.txt";

init.txt我有psservice \\\\ip -u user -p Calendar# restart spooler并且psservice是 exrta :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM