我在WPF应用程序(自托管)中有一个WCF服务,我有一个典型的错误"你的进程没有对这个命名空间的访问权限".用户不能拥有管理员权限,因此使用.manifest不是解决方案.端口是动态的,应用程序每次运行时都会计算一个空闲端口,因此应用程序必须通过netsh多次插入监听端口我使用带有域管理员的ProcessStartInfo,但要启动该进程,用户需要管理员权限.以管理员身份运行应用程序既不是解决方案,所以我需要普通用户可以运行应用程序,程序通过netsh作为域管理员添加端口.
我的过程是这样的:
ProcessStartInfo psi = new ProcessStartInfo("netsh", parameter);
SecureString ss = new SecureString();
for (int i = 0; i < adminPass.Length; i++)
ss.AppendChar(adminPass[i]);
psi.Password = ss;
psi.UserName = Admin;
psi.Domain = Domain;
psi.Verb = "runas";
psi.RedirectStandardOutput = false;
psi.CreateNoWindow = true;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.UseShellExecute = false;
Process.Start(psi);
Run Code Online (Sandbox Code Playgroud)
非常感谢
我一直在尝试在PowerShell上运行以下命令:
netsh http add sslcert ipport=0.0.0.0:443 certhash=<some certhash> appid={<random guid>}
Run Code Online (Sandbox Code Playgroud)
问题是,它"The parameter is incorrect"
每次都会返回.我检查了证书哈希号码和生成的guid,他们都没问题.实际上,我运行了相同的命令cmd.exe
并且它工作得很好,这增加了挫败感.
我想将变量作为certhash
和传递appid
,这就是我使用PowerShell的原因.
如果有人可以帮助我理解为什么它不起作用或者是否有缺少它可以在PowerShell上工作.
有没有办法在Windows 7(或更高版本)上使用命令行启用"Internet连接共享" ?也许使用"netsh"或类似的命令?
在为自主主机Owin控制台应用程序设置HTTP时出现问题.浏览器始终显示连接重置错误.
我已尝试根据此链接http://chavli.com/how-to-configure-owin-self-hosted-website-with-ssl/手动创建证书,但我仍然在该端口上遇到连接重置问题.我已经检查了Windows事件日志,并且没有错误消息.
应用程序将自行创建X509证书并自动运行netsh命令.
没有Ssl,应用程序可以正确显示网页.
任何人都可以在下面运行我的代码并查看它是否可以在您的计算机上运行?提前致谢.
需要添加COM引用CertEnroll 1.0 Type Library来编译下面的代码(vs2015已在类型库中包含此COM引用)
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using CERTENROLLLib;
using Microsoft.Owin.Hosting;
using AppFunc = System.Func<System.Collections.Generic.IDictionary<string, object>, System.Threading.Tasks.Task>;
namespace Owin.Startup
{
class Program
{
static void Main(string[] args)
{
int port = 8888;
string url = $"https://localhost:{port}";
var cert = GetCert("localhost", TimeSpan.FromDays(3650), "devpwd", AppDomain.CurrentDomain.BaseDirectory + "cert.dat");
ActivateCert(cert, port, GetAppId());
using (WebApp.Start<Startup>(url))
{
Console.WriteLine($"Hosted: {url}");
Console.ReadLine(); …
Run Code Online (Sandbox Code Playgroud) 重要编辑:再次回到这个主题.正如您所说,应该没有默认NIC,我试图了解是否有办法检测实际连接的所有NIC.
拥有我的物理接口的MAC地址有一种编程方式来获取接口名称/接口状态/等...
例如,我的XP机器:
器件Realtek RTL8139系列PCI快速以太网NIC MAC XXXX-XXXX-XXXX
XXXX-XXXX-XXXX就是我所知道的
通过此设备,我使用"本地连接"连接进行连接(所有信息都与网关,子网等相关)
所以我正在搜索XXXX-XXXX-XXXX和本地连接之间的链接.
希望现在一切都清楚了.
谢谢大家!PS抱歉延迟... +1投票给所有人,耐心等待!
老问题
大家好,我想使用命令netsh更改"本地连接"的IP.
我的问题是有一种编程方式来获取默认连接名称(即恰好是"本地连接")?
谢谢
编辑:我不需要所有连接名称的列表,但只需要默认列表.访问注册表我得到列表,似乎默认标记为*.不幸的是,在控制台上打印它们有点像10种不同的"局域连接"...
Local Area Connection* 13
6TO4 Adapter
VMware Network Adapter VMnet1
Wireless Network Connection 2
Reusable ISATAP Interface {483968F2-DBF9-4596-B8BE-725FAAB89F93}
Local Area Connection* 3
Local Area Connection* 2
Reusable Microsoft 6To4 Adapter
Local Area Connection* 7
VMware Network Adapter VMnet8
Local Area Connection* 8
isatap.replynet.prv
Local Area Connection* 9
Local Area Connection* 12
isatap.{FAA80CE0-D641-408A-83F8-5F9C394FFD76}
Bluetooth Network Connection
Local Area Connection* 4
isatap.{40156BF9-6599-4912-A315-62DE5342B452}
isatap.{7651F2F5-4888-4258-92C5-6822C506D726} …
Run Code Online (Sandbox Code Playgroud) 我想通过dos将网络接口名称重命名为默认名称,例如“以太网”。
\n\n我知道netsh interface set interface name=\xe2\x80\x9dLocal Area Connection\xe2\x80\x9d newname=\xe2\x80\x9dEthernet\xe2\x80\x9d
就是这样做的方法。
我正在运行一个脚本,它不知道接口的名称,对吗?因此,在设置接口的 IP 地址之前,我需要它将其重命名为默认值。
\n\n在不知道接口名称的情况下如何做到这一点?
\n\n有没有办法以某种方式获取接口的名称然后更改它?
\n有没有办法删除特定端口的每个 urlacl 保留。
我的意思是这样的事情是可能的(客户星座):
netsh http add urlacl url=http://localhost:55521/ user="everyone"
netsh http add urlacl url=http://+:55521/ user="everyone"
Run Code Online (Sandbox Code Playgroud)
现在我想删除55521端口的所有保留,这可以是任何ip星座!
顺便说一句,我在 ac# 应用程序中使用 nancy 自主机执行此操作。
我试图在powershell ps1文件中使用netsh http添加sslcert,但它不断抛出错误:
$guid = [guid]::NewGuid()
netsh http add sslcert ipport=0.0.0.0:443 certhash=5758B8D8248AA8B4E91DAA46F069CC1C39ABA718 appid={$guid}
'JABnAHUAaQBkAA' is not a valid argument for this command.
The syntax supplied for this command is not valid. Check help for the correct syntax.
Usage: add sslcert [ipport=]<IP Address:port>
[certhash=]<string>
[appid=]<GUID>
[[certstorename=]<string>
[verifyclientcertrevocation=]enable|disable
[verifyrevocationwithcachedclientcertonly=]enable|disable
[usagecheck=]enable|disable
[revocationfreshnesstime=]<u-int>
[urlretrievaltimeout=]<u-int>
[sslctlidentifier=]<string>
[sslctlstorename=]<string>
[dsmapperusage=]enable|disable
[clientcertnegotiation=]enable|disable]
Run Code Online (Sandbox Code Playgroud)
参数:
Tag Value
ipport - IP address and port for the binding.
certhash - The SHA hash of the certificate. This hash
is 20 bytes long …
Run Code Online (Sandbox Code Playgroud) 我已经通过 C# (bouncycastle) 创建了自签名 SSL 证书。它显示在本地计算机/个人商店中,看起来与 Microsoft 现有的本地主机证书完全相同。如果我显示属性,它会说:
SSL 证书添加失败,错误:1312 指定的登录会话不存在。它可能已经被终止了。
但是,如果我想通过 netsh 注册此证书,则会收到错误:
netsh.exe http add sslcert ipport=0.0.0.0:{0} certhash={1} appid={2}
Run Code Online (Sandbox Code Playgroud)
app-id 是在 assemblyinfo.cs 中指定的 GUID。certhash
是来自证书属性页的哈希值。
我在许多博客文章中发现了导致这种情况发生的几个原因:
他们都没有取得成功......
我正在尝试从网络适配器中删除静态配置的 DNS 地址。我可以看到存在等效的 netsh 命令:
netsh interface ipv6 delete dns <adaptername> all
但我需要使用 powershell cmdlet 来执行此操作。目前我还没有找到任何谈论这个的参考资料。大多数线程将我指向 DNSServer 模块,但我所需要的只是删除客户端计算机中配置的 DNS。有人可以帮忙吗?
netsh ×10
c# ×3
powershell ×3
ssl ×3
cmd ×2
command-line ×2
self-hosting ×2
windows ×2
binding ×1
ethernet ×1
guid ×1
http ×1
https ×1
nancy ×1
networking ×1
owin ×1
wcf ×1
windows-7 ×1
windows-8 ×1
wpf ×1