Reputation: 826
I wrote a simple c# program to automate the process of signing files and I just can't get it to work. Sorry, but I'm no expert in C# (obviously)! Here's my code:
static void Main(string[]
// This progam makes it easy to remember the parameters that need to be passed to signtool and automates the process
if (args.Length < 3)
{
Console.WriteLine("Usage: SignFile FileToSign .pfxfile Password");
}
else
{
try
{
string signTool = "\"C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\Bin\\signtool.exe\"";
string fileToSign = args[0];
string pfxFile = args[1];
string password = args[2];
string commandLine = "/C " + signTool + " sign /f \"" + pfxFile + "\" /fd SHA256 /p "
+ password + @" /t http://timestamp.verisign.com/scripts/timestamp.dll " + fileToSign;
ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.FileName = "cmd.exe";
System.IO.Directory.SetCurrentDirectory(".");
startInfo.Arguments = commandLine;
Process process = new Process();
startInfo.UseShellExecute = false;
process.StartInfo = startInfo;
process.Start();
}
catch (Exception e)
{
Console.WriteLine("Error: " + e.Message);
throw;
}
}
}
When I run it I get 'C:\Program' is not recognized as an internal or external command.
I also tried using the short version of the directory name:
string signTool = "\"c:\\PROGRA~2\\MICROS~2\\Windows\\v7.0A\\Bin\\signtool.exe\"";
But this I get:
The filename, directory name, or volume label syntax is incorrect.
I could say more, but I think I'll leave this as simple as it is...
Upvotes: 1
Views: 119
Reputation: 30267
Try it with @ in front, like this:
string signTool = @"""C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\signtool.exe""";
Upvotes: 2