Add ports with netsh in WCF as domain admin withou

2019-06-21 09:51发布

问题:

I have a service with WCF in a WPF application (self-hosted) and I have the typical error "Your process does not have access rights to this namespace". The users can’t have admin privileges so using a .manifest is not a solution. The ports are dynamic, the application calculate a free port every time is running, so the application must insert the listen port by netsh several times I use a ProcessStartInfo with domain administrator, but to start the process the user needs admin privileges. Run the application as administrator neither is a solution, so I need that a normal user can run the application and the program add the port by netsh as domain administrator.

My Process is something like this:

    ProcessStartInfo psi = new ProcessStartInfo("netsh", parameter);
        SecureString ss = new SecureString();

            for (int i = 0; i < adminPass.Length; i++)
                ss.AppendChar(adminPass[i]);

            psi.Password = ss;
            psi.UserName = Admin;
            psi.Domain = Domain;
            psi.Verb = "runas";
            psi.RedirectStandardOutput = false;
            psi.CreateNoWindow = true;
            psi.WindowStyle = ProcessWindowStyle.Hidden;
            psi.UseShellExecute = false;
            Process.Start(psi);

Thanks a lot

回答1:

Take a look at the accepted answer for this Stack Overflow question for a possible solution to your problem. The approach outlined in the answer is to break out the admin-requiring code out into a Windows service which performs the elevated privilege operations under an appropriate (separate) account when invoked.



标签: c# wpf wcf netsh