Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法通过C#启动进程。也许是因为空白_C#_Command Line - Fatal编程技术网

无法通过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\”)