且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-02-15 22:46:12

我的解决方案:

    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.