KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to create a tool that converts the dynamic DHCP-provided IPv4 address, gateway and dns-settings into static configuration. I've tried to use WMI to solve this puzzle, but I have a problem I can't figure out. The application completes, DNS and Gateway is configured, but the EnableStatic method (to set the IP address and subnet) has been unsuccesful which means that the IP is still received from DHCP (with greyed out fields) even though the default gateway has been set. How do I fix this? The ReturnValue from EnableStatic is 70 (Invalid IP address). The weird thing is that the input parameters are the same that I extracted from the NIC 2 seconds earlier. Here is the code (except GUI), http://pastebin.com/AE3dGhUz : using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Management; namespace Static_NIC_Settings_Creator { public partial class Form1 : Form { private ManagementObjectCollection queryCollection; private string[] networkInterfaces; private int currentNIC; private string[] ipAddress; private string[] subnetMask; private string[] defaultIPGateway; private string[] dnsServerSearchOrder; public Form1() { InitializeComponent(); getNICs(); } private void convertButton_Click(object sender, EventArgs e) { if (networkInterfaces.Count() > 0) { //Get current NIC settings if (!getNICSettings()) { MessageBox.Show("Retrieving current NIC settings failed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //Convert to stati
Tags (comma-separated)
Save Edits
Cancel