简体   繁体   English

从 C# 运行 exe

[英]Run an exe from C#

i have a problem to call PsService from C# code.我在从 C# 代码调用 PsService 时遇到问题。 when i wrote psservice \\\\ip -u user -p Calendar# restart spooler (init.txt) from cmd it's ok, but in C# i had problem.当我从 cmd 写psservice \\\\ip -u user -p Calendar# restart spooler (init.txt) 时,它没问题,但在 C# 中我遇到了问题。 my code :我的代码:

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();

then i run bin\\debug\\myExe from cmd but wrote this:然后我从 cmd 运行 bin\\debug\\myExe 但写了这个:

Use the username and password to log into remote computer in cases where you account does not have permissions to perform the action you specify.如果您的帐户无权执行您指定的操作,请使用用户名和密码登录远程计算机。

If you know the cmd code works well then the easiest way is to call whatever your exe application through cmd.如果您知道 cmd 代码运行良好,那么最简单的方法是通过 cmd 调用您的任何 exe 应用程序。 Don't go into mess.不要陷入混乱。

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

Replace [enter cmd code] without square brackets [ ]替换[enter cmd code]不带方括号 [ ]

i had a silly mistake :)我犯了一个愚蠢的错误:)

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

in init.txt i had psservice \\\\ip -u user -p Calendar# restart spooler and psservice was exrta :)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