Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add ports with netsh in WCF as domain admin without admin privileges

Tags:

c#

wcf

wpf

netsh

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

like image 321
user1142778 Avatar asked Nov 13 '22 11:11

user1142778


1 Answers

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.

like image 134
Sixto Saez Avatar answered Nov 16 '22 02:11

Sixto Saez