我想通过以下代码以编程方式保留端口和端口绑定(bind):
private void PortReserve()
{
try
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new
System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
startInfo.FileName = "cmd.exe";
startInfo.UseShellExecute = true;
startInfo.Arguments = @"/c netsh http add urlacl url=https://127.0.0.1:8083/ user=EVERYONE";
process.StartInfo = startInfo;
process.Start();
}
catch (Exception ex)
{
throw ex;
}}
对于端口绑定(bind): 将 startInfo.Arguments 的参数替换为 @"/c netsh http add sslcert ipport=127.0.0.1:8083 certhash=df03c4b0b32f3302a3b70abe6b5dfd864d0986a5 appid={00112233-4455-6677-8899-CCBBCCcertiation} =启用";
以上命令在 win 7 , win servers 和 8 机器上运行完美,但是当涉及到 Win xp 它开始在 CMD 中抛出错误: 未找到以下命令 http add urlacl url=https://127.0.0.1:8083 user=Everyone
我检查在所有机器的mmc中成功导入的证书。
遇到这种情况怎么办?
请您参考如下方法:
根据 MSDN你不能在 xp 中使用 netsh。
If you are running Windows Server 2003 or Windows XP, use the HttpCfg.exe tool. With Windows Server 2003 this tool is installed. With Windows XP, you can download the tool at Windows XP Service Pack 2 Support Tools. For more information, see Httpcfg Overview. The Windows Support Tools documentation explains the syntax for the Httpcfg.exe tool.
