C#Installer对不同exe的调用不起作用

时间:2015-08-10 18:32:44

标签: c# windows process cmd installer

我有一个安装程序(installer.exe),可以调用另一个安装程序(subinstaller.exe)。这是我触发其他安装程序的方式:

public void Run(String commandName, params String[] args)
{
    var commandProcess = new Process();

    commandProcess.StartInfo.FileName = "cmd.exe";
    commandProcess.StartInfo.RedirectStandardInput = true;
    commandProcess.StartInfo.RedirectStandardOutput = true;
    commandProcess.StartInfo.RedirectStandardError = true;
    commandProcess.StartInfo.CreateNoWindow = true;
    commandProcess.StartInfo.UseShellExecute = false;
    commandProcess.EnableRaisingEvents = true;

    var arguments = String.Join(" ", args);
    var command = String.Format("/C \"\"{0}\" {1}\"", commandName, arguments);
    commandProcess.StartInfo.Arguments = command;

    using (commandProcess)
    {
        commandProcess.Start();

        var errors = commandProcess.StandardError.ReadToEnd();
        if (String.IsNullOrEmpty(errors) == false)
        {
            var message = String.Format("A problem occurred while running \"{0}\": {1}", command, errors);
            throw new Exception(message);
        }

        commandProcess.WaitForExit();
    }
}

导致我麻烦的命令最终会出现以下情况:

cmd.exe /C ""C:\Updater\subinstaller.exe" /norestart /silent /serial="TRIAL""

如果我在命令提示符下运行该命令,一切都按预期工作。但是,如果我通过上述过程(commandNameC:\Updater\subinstaller.exe)运行它,那么它就无法正常运行。我认为这是因为许可问题,但我已经有效地排除了这一点:

  1. 我的最高级别安装程序通过需要提升权限的清单以管理员身份运行。我已经单独验证了启动的cmd.exe进程是在相同的提升权限下运行的。
  2. 我明确地让它在SYSTEM和本地管理员帐户下运行,这两个帐户也都无效。
  3. 我真的想知道可能导致问题的原因。考虑到它在原始命令行中工作,它不太可能是子安装程序。有没有人有任何想法?

    更新

    我还尝试将cmd排除在等式之外:

    public void Run(String commandName, params String[] args)
    {
        var commandProcess = new Process();
    
        commandProcess.StartInfo.FileName = commandName;
        commandProcess.StartInfo.RedirectStandardInput = true;
        commandProcess.StartInfo.RedirectStandardOutput = true;
        commandProcess.StartInfo.RedirectStandardError = true;
        commandProcess.StartInfo.CreateNoWindow = true;
        commandProcess.StartInfo.UseShellExecute = false;
        commandProcess.EnableRaisingEvents = true;
    
        var arguments = String.Join(" ", args);
        commandProcess.StartInfo.Arguments = arguments;
    
        using (commandProcess)
        {
            commandProcess.Start();
    
            var errors = commandProcess.StandardError.ReadToEnd();
            if (String.IsNullOrEmpty(errors) == false)
            {
                var message = String.Format("A problem occurred while running \"{0}\": {1}", commandName, errors);
                throw new Exception(message);
            }
    
            commandProcess.WaitForExit();
    
            if (commandProcess.ExitCode != 0)
            {
                var message = String.Format("A problem occurred while running \"{0}\": Exit code {1}", commandName, commandProcess.ExitCode);
                throw new Exception(message);
            }
        }
    }
    

0 个答案:

没有答案