【问题标题】:How I can execute a exe file with parameter in C# with my User ?如何使用我的用户在 C# 中执行带有参数的 exe 文件?
【发布时间】:2014-05-27 09:48:30
【问题描述】:

使用进程类执行带参数的 exe 的网络应用程序。我的问题是它可以运行几天,但现在我不能使用参数 -.- 执行这个 exe -

如果我使用终端手动尝试它,它会起作用,但如果我使用 C# 代码这样做,我会收到一条消息,说我无法创建文件。

*** ERROR *** Cannot create qrun.inf file

这是我的 C# 代码:

string cmd = Server.MapPath(@"~/exe/lstc_qrun.exe -s server01 -R");

string output = ExecuteCommand(cmd);

//Output = "*** ERROR *** Cannot create qrun.inf file"

这里是 ExecuteCommand 方法:

public static string ExecuteCommand(string command)
        {
            int exitCode;
            ProcessStartInfo processInfo;
            Process process;

            try
            {
                processInfo = new ProcessStartInfo("cmd.exe", "/c " + command);
                processInfo.CreateNoWindow = true;
                processInfo.UseShellExecute = false;
                processInfo.RedirectStandardError = true;
                processInfo.RedirectStandardOutput = true;


                using (process = Process.Start(processInfo))
                {
                    string output = process.StandardOutput.ReadToEnd();
                    exitCode = process.ExitCode;

                    return output;
                }

            }
            catch (Exception ex)
            {
                return "error: " + ex.Message;
            }

        }

我能做什么..我在本地机器上工作:(

【问题讨论】:

    标签: c# asp.net windows process exe


    【解决方案1】:

    检查this Process.Start() 的引用:

    public static Process Start(
        string fileName,
        string arguments,
        string userName,
        SecureString password,
        string domain
    )
    

    或者你可以只填写 ProcessStartInfo 成员:

    processInfo.Username = 'Username' ;
    processInfo.Password = 'Password' ;
    processInfo.Domain  = 'MyDomain' ; 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-27
      • 2013-04-02
      • 1970-01-01
      • 1970-01-01
      • 2016-07-26
      • 1970-01-01
      相关资源
      最近更新 更多