|
6 | 6 | using System.Net; |
7 | 7 | using System.Net.NetworkInformation; |
8 | 8 | using System.Threading.Tasks; |
| 9 | +using System.Windows; |
9 | 10 |
|
10 | 11 | namespace NETworkManager.Models.Network |
11 | 12 | { |
@@ -129,22 +130,22 @@ public Task ConfigureNetworkInterfaceAsync(NetworkInterfaceConfig config) |
129 | 130 | public void ConfigureNetworkInterface(NetworkInterfaceConfig config) |
130 | 131 | { |
131 | 132 | // IP |
132 | | - string command = string.Format("netsh interface ipv4 set address name=\"{0}\" ", config.Name); |
133 | | - command += config.EnableStaticIPAddress ? string.Format("source=static address={0} mask={1} gateway={2}", config.IPAddress, config.Subnetmask, config.Gateway) : "source=dhcp"; |
| 133 | + string command = @"netsh interface ipv4 set address name='" + config.Name + @"'"; |
| 134 | + command += config.EnableStaticIPAddress ? @" source=static address=" + config.IPAddress + @" mask=" + config.Subnetmask + @" gateway=" + config.Gateway : @" source=dhcp"; |
134 | 135 |
|
135 | 136 | // DNS |
136 | | - command += string.Format(";netsh interface ipv4 set DNSservers name=\"{0}\" ", config.Name); |
137 | | - command += config.EnableStaticDNS ? string.Format("source=static address={0} register=primary validate=no", config.PrimaryDNSServer) : "source=dhcp"; |
138 | | - command += (config.EnableStaticDNS && !string.IsNullOrEmpty(config.SecondaryDNSServer)) ? string.Format(";netsh interface ipv4 add DNSservers name=\"{0}\" address={1} index=2 validate=no", config.Name, config.SecondaryDNSServer) : ""; |
| 137 | + command += @";netsh interface ipv4 set DNSservers name='" + config.Name + @"'"; |
| 138 | + command += config.EnableStaticDNS ? @" source=static address=" + config.PrimaryDNSServer + @" register=primary validate=no" : @" source=dhcp"; |
| 139 | + command += (config.EnableStaticDNS && !string.IsNullOrEmpty(config.SecondaryDNSServer)) ? @";netsh interface ipv4 add DNSservers name='" + config.Name + @"' address=" + config.SecondaryDNSServer + @" index=2 validate=no" : ""; |
139 | 140 |
|
140 | 141 | // Start process with elevated rights... |
141 | 142 | ProcessStartInfo processStartInfo = new ProcessStartInfo() |
142 | 143 | { |
143 | 144 | Verb = "runas", |
144 | 145 | FileName = "powershell.exe", |
145 | | - Arguments = string.Format("-NoProfile -NoLogo -Command {0}", command) |
| 146 | + Arguments = "-NoProfile -NoLogo -Command " + command |
146 | 147 | }; |
147 | | - |
| 148 | + |
148 | 149 | processStartInfo.WindowStyle = ProcessWindowStyle.Hidden; |
149 | 150 |
|
150 | 151 | using (Process process = new Process()) |
|
0 commit comments