一个最重要的问题就是,在XP系统下执行是可以的,但在Vista系统下却改不了IP。这一段是取获取Ip,子网掩码,网关的,在XP系统和Vista系统都可以用,说明Win32_NetworkAdapterConfiguration在Vista系统没什么问题。mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
moc = mc.GetInstances();foreach (ManagementObject mo in moc)
{
if (Convert.ToBoolean(mo["ipEnabled"]))
{
// 获取Ip,子网掩码,网关
ipAddress = (mo["IPAddress"] as string[])[0];
ipSubNetMask = (mo["IPSubnet"] as string[])[0];
ipGateway = (mo["DefaultIPGateway"] as string[])[0];下面的代码是对本地IP进行赋值的,在XP系统下可以更改,但在Vista系统下不能,不解foreach (ManagementObject mo in moc)
{
if (!(bool)mo["ipEnabled"])
continue;
//设置ip地址和子网掩码
inPar = mo.GetMethodParameters("EnableStatic");
inPar["IPAddress"] = new string[] { "192.168.1.11" };
inPar["SubnetMask"] = new string[] { "192.168.1.1"};
outPar = mo.InvokeMethod("EnableStatic", inPar, null);
上面的代码在Vista系统下怎么也改不了,不知道为什么,哪位大哥能给个答案啊,万分感谢!!!!
moc = mc.GetInstances();foreach (ManagementObject mo in moc)
{
if (Convert.ToBoolean(mo["ipEnabled"]))
{
// 获取Ip,子网掩码,网关
ipAddress = (mo["IPAddress"] as string[])[0];
ipSubNetMask = (mo["IPSubnet"] as string[])[0];
ipGateway = (mo["DefaultIPGateway"] as string[])[0];下面的代码是对本地IP进行赋值的,在XP系统下可以更改,但在Vista系统下不能,不解foreach (ManagementObject mo in moc)
{
if (!(bool)mo["ipEnabled"])
continue;
//设置ip地址和子网掩码
inPar = mo.GetMethodParameters("EnableStatic");
inPar["IPAddress"] = new string[] { "192.168.1.11" };
inPar["SubnetMask"] = new string[] { "192.168.1.1"};
outPar = mo.InvokeMethod("EnableStatic", inPar, null);
上面的代码在Vista系统下怎么也改不了,不知道为什么,哪位大哥能给个答案啊,万分感谢!!!!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货