WCF selfhosted service, installer class and netsh
Asked Answered
O

1

14

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"

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

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?

Osei answered 26/3, 2010 at 8:40 Comment(0)
O
25

My aproach to a solution:

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

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.

Osei answered 26/3, 2010 at 10:27 Comment(1)
@kevinc If you're referring to user=\, he isn't, because of the @ making it a verbatim string.Sclera

© 2022 - 2024 — McMap. All rights reserved.