WCF 自托管服务、安装程序类和 netsh [英] WCF selfhosted service, installer class and netsh

查看:22
本文介绍了WCF 自托管服务、安装程序类和 netsh的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a selfhosted WCF service application which I want to deploy by a msi installer package. The endpoint uses http port 8888. In order to startup the project under windows 2008 after installation I have to either run the program as administrator or have to edit the http settings with netsh:

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

我想从我的安装程序类中编辑 http 设置.因此,我从 Install() 方法调用以下方法:

I want to edit the http settings from my installer class. Therefore I call the following method from the Install() method:

    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 服务的权限?

This method will work for english versions of windows, but not for localized versions (The group Everyone has different names in localized versions). I have also tried to use Environment.UserName to allow access at least for the current logged on user. But this does also not work, because the installer class is run by the msi service which runs under the user SYSTEM. Hence Enviroment.UserName returns SYSTEM and that is not what I want.

Is there a way to grant access to all (or at least for the current logged on) user to my selfhosted WCF service from a msi installer class?

推荐答案

我的解决方案:

    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);
    }

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

The SID "S-1-1-0" is a wellknown SID and stands for the "Everyone" account. The SID is the same for all localizations of windows. The method Translate of SecurityIdentifier class returns the localized name of the Everyone account.

这篇关于WCF 自托管服务、安装程序类和 netsh的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆