Search code examples
c#winformscmdrunas

c# winforms Application, run a cmd command as system


I have written a program in the last days which automatically changes the proxy server. This runs as a Windows Forms Tray Application on the user level. Now came a request which caused me some problems. A cmd command "ipconfig /registerdns" should be executed but this requires higher permissions. I'm now looking for a way to easily execute this command in normal user context. Is there a way to run this one command as a system? Or any other possibility?

Or is there another function to re-register the dns without admin priviledge?

I hope there is a easy way.

Thank you very much!


Solution

  • Okay so I found no solution for my former problem, because it is not possible to launch a elevated command from a user Application. But I found a powershell command: Register-DnsClient. This command does the same and does not need elevated priviledges. Only downside is it works only on Windows 8.1 and newer. So Windows 7 is not supported.