首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

关于修改IP设置和NDS设置,该如何解决

2012-01-29 
关于修改IP设置和NDS设置VB codeFunction ChangeIP(IP As String, NM As String, GW As String, MDNS As S

关于修改IP设置和NDS设置

VB code
Function ChangeIP(IP As String, NM As String, GW As String, MDNS As String, SDNS As String) As String'返回值说明:返回一个设置的中文说明.    Dim strComputer, objWMIService, colNetAdapters, strIPAddress, strSubnetMask    Dim strGateway, strGatewaymetric, strDNS, objNetAdapter, errEnable, errGateways, errDNS    strComputer = "."    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")    Set colNetAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")    strIPAddress = Array(IP)  'ip地址    strSubnetMask = Array(NM) '子网掩码    strGateway = Array(GW)    '网关    strDNS = Array(MDNS, SDNS) '主DNS各备DNS    strGatewaymetric = Array(1)        For Each objNetAdapter In colNetAdapters        errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)        errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)        errDNS = objNetAdapter.SetDNSServerSearchOrder(strDNS)        If errEnable = 0 And errGateways = 0 And errDNS = 0 Then            ChangeIP = "设置成功"        Else            If errEnable = 0 Then                ChangeIP = "IP地址和子网掩码设置成功, "            Else                ChangeIP = "IP地址或子网掩码设置失败, "            End If            If errGateways = 0 Then                ChangeIP = ChangeIP & "默认网关设置成功, "            Else                ChangeIP = ChangeIP & "默认网关设置失败, "            End If            If errDNS = 0 Then                ChangeIP = ChangeIP & "DNS设置成功"            Else                ChangeIP = ChangeIP & "DNS设置失败"            End If        End If    Next    End FunctionPrivate Sub Command1_Click()    MsgBox ChangeIP("192.168.1.12", "255.255.255.0", "192.168.1.1", "8.8.8.8", "8.8.4.4")End Sub


如上,可以设置IP和DNS了,现在有个问题,如果我要还原设置成 自动获得P地址 和 自动获得NDS服务器地址 怎么处理?


[解决办法]
可否考虑清除前先的设置,再用 Set winIP = CreateObject("MSWinsock.Winsock") 获得呢?
[解决办法]
这种事其实不必兴师动众的, 简单两句语句就能解决:

shell"netsh -c interface dump > IPADD.txt" '这句用来将IP设置导出到配置文件

shell"netsh -f IPADD.txt" '这句用来将配置文件文本导入IP设置

IPADD.txt的内容如下:

XML code
#========================# 接口配置#========================pushd interfacereset allpopd# 接口配置结束#========================# 接口配置#========================pushd interface ipv6uninstallpopd# 接口配置结束# ----------------------------------# ISATAP 配置# ----------------------------------pushd interface ipv6 isatappopd# ISATAP 配置结束# ----------------------------------# 6to4 配置# ----------------------------------pushd interface ipv6 6to4resetpopd# 6to4 配置结束#=============# 端口代理配置#=============pushd interface portproxyresetpopd# 端口代理配置结束# ---------------------------------- # 接口 IP 配置         # ---------------------------------- pushd interface ip# "无线网络连接" 的接口 IP  配置set address name="无线网络连接" source=static addr=192.168.1.3 mask=255.255.255.0set address name="无线网络连接" gateway=192.168.1.1 gwmetric=0set dns name="无线网络连接" source=static addr=192.168.1.1 register=PRIMARYset wins name="无线网络连接" source=static addr=none# "本地连接" 的接口 IP  配置set address name="本地连接" source=dhcp set dns name="本地连接" source=dhcp register=PRIMARYset wins name="本地连接" source=dhcppopd# 接口 IP 配置结束 

热点排行