无法通过C#启动进程。也许是因为空白
我已经(在设置了调试器之后从调试器复制了它们,以确保实际传递给命令的是这些调试器): 但是当我无法通过C#启动进程。也许是因为空白,c#,command-line,C#,Command Line,我已经(在设置了调试器之后从调试器复制了它们,以确保实际传递给命令的是这些调试器): 但是当我Start()它没有给应用程序签名时。(当我将signtool复制到该文件夹并手动执行时,它会工作。) 因此,为了调试,我尝试: System.Diagnostics.Process.Start(@"cmd.exe", @" /k " + "\"" + process.StartInfo.FileName + "\"" + " " + "\"" + process.StartInfo.Arguments
Start()
它没有给应用程序签名时。(当我将signtool复制到该文件夹并手动执行时,它会工作。)
因此,为了调试,我尝试:
System.Diagnostics.Process.Start(@"cmd.exe", @" /k " + "\"" + process.StartInfo.FileName + "\"" + " " + "\"" + process.StartInfo.Arguments + "\"");
但我得到:
“C:\Program”未被识别为内部或外部命令,
可操作的程序或批处理文件
那么,我如何让签名生效(或者至少是cmd
,这样我就可以知道到底是什么问题了)
编辑:谢谢大家。问题的答案如下:缺少引用。虽然我在发帖前确实尝试过(在所有问题上加引号),但当时没有效果。事实证明,我在引号和实际参数之间添加了一些空白。因此,这似乎导致了一个错误 需要引用您的文件名
process.StartInfo.FileName = "\"C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\Bin\\signtool.exe\""
编辑
试着改用这个,这对我来说适用于虚拟文件
string filename = "\"C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\Bin\\signtool.exe\""
string arguments = "sign /f \"C:\\Users\\...\\myPfx.pfx\" /p \"myPassword\" \"C:\\Users\\...\\Desktop\\app.exe\""
Process.Start("cmd.exe /k " + filename + " " + arguments)
您的文件名需要被引用
process.StartInfo.FileName = "\"C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\Bin\\signtool.exe\""
编辑
试着改用这个,这对我来说适用于虚拟文件
string filename = "\"C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\Bin\\signtool.exe\""
string arguments = "sign /f \"C:\\Users\\...\\myPfx.pfx\" /p \"myPassword\" \"C:\\Users\\...\\Desktop\\app.exe\""
Process.Start("cmd.exe /k " + filename + " " + arguments)
您可能需要将WorkingDirectory属性设置为桌面(app.exe所在的位置),只需将“app.exe”(不带路径)传递给arguments属性。您可能需要将WorkingDirectory属性设置为桌面(app.exe所在的位置),只需传递“app.exe”(不带路径)请尝试创建一个ProcessStartInfo对象,然后将进程的StartInfo设置为新对象:
ProcessStartInfo startInfo = new ProcessStartInfo();
string filename = "\"C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\Bin\\signtool.exe\""
string arguments = " sign /f \"C:\\Users\\...\\myPfx.pfx\" /p \"myPassword\" \"C:\\Users\\...\\Desktop\\app.exe\""
startInfo.Arguments = filename + arguments;
startInfo.FileName = "cmd.exe";
startInfo.UseShellExecute = false;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.WorkingDirectory = "set your working directory here";
Process p = new Process();
p.StartInfo = startInfo;
p.Start();
string output = p.StandardOutput.ReadToEnd();
string error = p.StandardError.
//Instrumentation.Log(LogTypes.ProgramOutput, output);
//Instrumentation.Log(LogTypes.StandardError, error);
p.WaitForExit();
if (p.ExitCode == 0)
{
// log success;
}
else
{
// log failure;
}
请尝试此操作,创建一个ProcessStartInfo对象,然后将进程的StartInfo设置为新对象:
ProcessStartInfo startInfo = new ProcessStartInfo();
string filename = "\"C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\Bin\\signtool.exe\""
string arguments = " sign /f \"C:\\Users\\...\\myPfx.pfx\" /p \"myPassword\" \"C:\\Users\\...\\Desktop\\app.exe\""
startInfo.Arguments = filename + arguments;
startInfo.FileName = "cmd.exe";
startInfo.UseShellExecute = false;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.WorkingDirectory = "set your working directory here";
Process p = new Process();
p.StartInfo = startInfo;
p.Start();
string output = p.StandardOutput.ReadToEnd();
string error = p.StandardError.
//Instrumentation.Log(LogTypes.ProgramOutput, output);
//Instrumentation.Log(LogTypes.StandardError, error);
p.WaitForExit();
if (p.ExitCode == 0)
{
// log success;
}
else
{
// log failure;
}
这仍然不能解决从
process.Start()开始时的问题代码>否。我的意思是,当我启动第一个进程(带有StartInfo
,没有“cmd.exe”)时,它不起作用。好吧,这也是我的第一个答案。尝试只运行Process.Start(@“\”C:\Program Files\Microsoft SDK\Windows\v7.1\Bin\signtool.exe\”)我试过了。正如我所说的,它不起作用。我甚至不知道为什么。它没有给我一个错误。谢谢。这就是问题所在。虽然我在发帖前确实尝试过(在所有问题上加引号),但当时没有效果。事实证明,我在引号和实际参数之间添加了一些空白。因此,这似乎导致了一个错误。再次感谢。这仍然不能解决从process.Start()开始时的问题代码>否。我的意思是,当我启动第一个进程(带有StartInfo
,没有“cmd.exe”)时,它不起作用。好吧,这也是我的第一个答案。尝试只运行Process.Start(@“\”C:\Program Files\Microsoft SDK\Windows\v7.1\Bin\signtool.exe\”)我试过了。正如我所说的,它不起作用。我甚至不知道为什么。它没有给我一个错误。谢谢。这就是问题所在。虽然我在发帖前确实尝试过(在所有问题上加引号),但当时没有效果。事实证明,我在引号和实际参数之间添加了一些空白。因此,这似乎导致了一个错误。再次感谢。谢谢你详细的回答。我接受了其他人的回答,因为他已经为我指明了方向,并且解决了问题(尽管这确实花了我一些时间。)再次感谢。向上投票。谢谢你详细的回答。我接受了其他人的回答,因为他已经为我指明了方向,并且解决了问题(尽管这确实花了我一些时间。)再次感谢。向上投票。