tags:

views:

308

answers:

1

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?

+1  A: 

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.

related questions