WCF自主服务,安装程序类和netsh

我有一个自主的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,但不适用于本地化版本(群组Everyone在本地化版本中具有不同的名称).我也试图使用Environment.UserName来允许至少访问当前登录用户.但是这也不行,因为安装程序类由在用户SYstem下运行的msi服务运行.因此Enviroment.UserName返回SYstem,这不是我想要的.有没有办法向msi安装程序类的所有(或至少为当前登录的)用户授予对我自己的主机WCF服务的访问权限?

我的解决方案:
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”帐户. Windows的所有本地化版本都相同.方法Translate of SecurityIdentifier类返回Everyone帐户的本地化名称.

相关文章

Windows2012R2备用域控搭建 前置操作 域控主域控的主dns:自...
主域控角色迁移和夺取(转载) 转载自:http://yupeizhi.blo...
Windows2012R2 NTP时间同步 Windows2012R2里没有了internet时...
Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...