sách gpt4 ai đã đi

WCF 自托管服务、安装程序类和 netsh

In lại 作者:行者123 更新时间:2023-12-03 21:23:17 29 4
mua khóa gpt4 Nike

我有一个自托管的 WCF 服务应用程序,我想通过 msi 安装程序包部署它。端点使用 http 端口 8888。为了在安装后在 windows 2008 下启动项目,我必须以管理员身份运行程序或必须使用 netsh 编辑 http 设置:

"netsh http add urlacl url=http://+:8888/ user=\Everyone"

我想从我的安装程序类中编辑 http 设置。因此,我从 Install() 方法调用以下方法:
    public void ModifyHttpSettings()
{
string parameter = @"http add urlacl url=http://+:8888/ user=\Everyone";

System.Diagnostics.ProcessStartInfo psi =
new System.Diagnostics.ProcessStartInfo("netsh", parameter);

psi.Verb = "runas";
psi.RedirectStandardOutput = false;
psi.CreateNoWindow = true;
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
psi.UseShellExecute = false;
System.Diagnostics.Process.Start(psi);
}

此方法适用于英文版本的 windows,但不适用于本地化版本(每个人在本地化版本中有不同的名称)。我还尝试使用 Environment.UserName 来允许至少当前登录用户的访问。但这也不起作用,因为安装程序类由在用户 SYSTEM 下运行的 msi 服务运行。因此 Enviroment.UserName 返回 SYSTEM 而这不是我想要的。有没有办法从 msi 安装程序类授予所有(或至少为当前登录的)用户访问我的自托管 WCF 服务的权限?

1 Câu trả lời

我的解决方法:

    public void ModifyHttpSettings()
{
string everyone = new System.Security.Principal.SecurityIdentifier(
"S-1-1-0").Translate(typeof(System.Security.Principal.NTAccount)).ToString();

string parameter = @"http add urlacl url=http://+:8888/ user=\" + everyone;

ProcessStartInfo psi = new ProcessStartInfo("netsh", parameter);

psi.Verb = "runas";
psi.RedirectStandardOutput = false;
psi.CreateNoWindow = true;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.UseShellExecute = false;
Process.Start(psi);
}

SID“S-1-1-0”是众所周知的SID,代表“Everyone”帐户。窗口的所有本地化的 SID 都是相同的。 SecurityIdentifier 类的 Translate 方法返回 Everyone 帐户的本地化名称。

关于WCF 自托管服务、安装程序类和 netsh,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2521950/

29 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com