public void SetIP(SetIpProperties ipProperties) { using (var networkConfigMng = new ManagementClass("Win32_NetworkAdapterConfiguration")) { ManagementClass objMC = new ManagementClass("Win32_NetworkAdapterConfiguration"); ManagementObjectCollection objMOC = objMC.GetInstances(); foreach (ManagementObject objMO in objMOC) { if ((bool)objMO["IPEnabled"]) { if (objMO["MACAddress"].Equals(ipProperties.MacName)) { string ethernet = "Ethernet"; File.WriteAllText(@"c:\temp\ipSet.bat", "netsh interface ip set address " + '"' + ethernet + '"' + " static " + ipProperties.ipAddress + " " + ipProperties.subnet + " " + ipProperties.gateway + " " + "1 " + "\r\nnetsh interface ip set dns " + '"' + ethernet + '"' + " static " + ipProperties.dns, Encoding.Default); File.WriteAllText(@"c:\MAMP\htdocs\ip.txt", ipProperties.ipAddress, Encoding.Default); //System.Diagnostics.Process proc = new System.Diagnostics.Process(); //proc.StartInfo.UseShellExecute = false; //proc.StartInfo.Domain = "HQMCDSOFT"; //proc.StartInfo.UserName = "******"; //proc.StartInfo.Password = ReadPassword("Erich1970Maria"); //proc.StartInfo.FileName = @"C:\temp\ipSet.bat — ярлык.lnk"; //proc.StartInfo.WorkingDirectory = @"c:\temp"; //proc.Start(); Process.Start(@"C:\temp\ipSet.bat — ярлык.lnk"); } } } } }
public void SetSettingsIP(SetIpProperties request) { SettingsIp settingsIp = new SettingsIp(); settingsIp.SetIP(request); }