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

被刻印的时光 ゝ 提交于 2019-12-10 14:01:55

问题


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.



来源:https://stackoverflow.com/questions/8816493/add-ports-with-netsh-in-wcf-as-domain-admin-without-admin-privileges

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!