Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.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# - Fatal编程技术网

C# 这应该很简单,但我可以';我不能让它工作

C# 这应该很简单,但我可以';我不能让它工作,c#,C#,我编写了一个简单的c#程序来自动化文件签名过程,但我就是无法让它工作。对不起,我不是C#方面的专家(显然)!这是我的密码: 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)

我编写了一个简单的c#程序来自动化文件签名过程,但我就是无法让它工作。对不起,我不是C#方面的专家(显然)!这是我的密码:

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;
            }
        }
    }
但我得到的是:

The filename, directory name, or volume label syntax is incorrect.

我可以说得更多,但我想我会让它保持简单…

用前面的@试试,如下所示:

string signTool = @"""C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\signtool.exe""";

在前面用@试试,如下所示:

string signTool = @"""C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\signtool.exe""";

关于我的原始问题的评论2修正了该错误:


关于我的原始问题的评论2修正了错误:


尝试使用字符串signTool=“c:\\PROGRA~2\\MICROS~2\\Windows\\v7.0A\\Bin\\signTool.exe\”;请参阅使用cmd.exe而不是直接调用该工具是否有原因?关于我得到的注释1:文件名、目录名或卷标语法不正确。请尝试使用字符串signTool=“c:\\PROGRA~2\\MICROS~2\\Windows\\v7.0A\\Bin\\signTool.exe\”;请参阅使用cmd.exe而不是直接调用该工具是否有原因?关于注释1,我得到:文件名、目录名或卷标语法不正确。