vb修改ip代码
3个回答
展开全部
在菜单中的【工程】—【引用】下,添加“Microsoft WMI Scripting V1.1 Library”,然后在Form1窗体上添加1个Combo1、Text1(0)、Text1(1)、Text1(2)、Text1(3)和Command1、Command2,代码如下:
Option Explicit
Dim objSWbemServices As SWbemServices
Dim objSWbemObjectSet As SWbemObjectSet
Dim objSWbemObject As SWbemObject
'Text1(0)为IP地址、Text1(1)为子网掩码、Text1(2)为缺省网关、Text1(3)为DNS
Private Sub Form_Load()
Set objSWbemServices = GetObject("winmgmts:")
Set objSWbemObjectSet = objSWbemServices.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
For Each objSWbemObject In objSWbemObjectSet
Combo1.AddItem objSWbemObject.Description '添加本机上已经安装了TCP/IP协议的网卡
Next
Combo1.Text = Combo1.List(0)
Combo1.ListIndex = 0
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set objSWbemServices = Nothing
Set objSWbemObjectSet = Nothing
Set objSWbemObject = Nothing
End Sub
'当选择了网卡后,显示当前所选网卡的设置
Private Sub Combo1_Click()
Set objSWbemObjectSet = objSWbemServices.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where Description='" & Combo1.Text & "'")
For Each objSWbemObject In objSWbemObjectSet
If objSWbemObject.DHCPEnabled Then
Text1(0).Text = ""
Text1(1).Text = ""
Text1(2).Text = ""
If IsNull(objSWbemObject.DNSServerSearchOrder) Then
Text1(3).Text = ""
Else
Text1(3).Text = objSWbemObject.DNSServerSearchOrder(0)
End If
Else
Text1(0).Text = objSWbemObject.IPAddress(0)
Text1(1).Text = objSWbemObject.IPSubnet(0)
Text1(2).Text = objSWbemObject.DefaultIPGateway(0)
Text1(3).Text = objSWbemObject.DNSServerSearchOrder(0)
End If
Next
End Sub
'设置网卡的IP地址、子网掩码、缺省网关和DNS
Private Sub Command1_Click()
Set objSWbemObjectSet = objSWbemServices.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where Description='" & Combo1.Text & "'")
For Each objSWbemObject In objSWbemObjectSet
objSWbemObject.EnableStatic Array(Text1(0).Text), Array(Text1(1).Text)
objSWbemObject.SetGateways Array(Text1(2).Text)
objSWbemObject.SetDNSServerSearchOrder Array(Text1(3).Text)
Next
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Option Explicit
Dim objSWbemServices As SWbemServices
Dim objSWbemObjectSet As SWbemObjectSet
Dim objSWbemObject As SWbemObject
'Text1(0)为IP地址、Text1(1)为子网掩码、Text1(2)为缺省网关、Text1(3)为DNS
Private Sub Form_Load()
Set objSWbemServices = GetObject("winmgmts:")
Set objSWbemObjectSet = objSWbemServices.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
For Each objSWbemObject In objSWbemObjectSet
Combo1.AddItem objSWbemObject.Description '添加本机上已经安装了TCP/IP协议的网卡
Next
Combo1.Text = Combo1.List(0)
Combo1.ListIndex = 0
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set objSWbemServices = Nothing
Set objSWbemObjectSet = Nothing
Set objSWbemObject = Nothing
End Sub
'当选择了网卡后,显示当前所选网卡的设置
Private Sub Combo1_Click()
Set objSWbemObjectSet = objSWbemServices.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where Description='" & Combo1.Text & "'")
For Each objSWbemObject In objSWbemObjectSet
If objSWbemObject.DHCPEnabled Then
Text1(0).Text = ""
Text1(1).Text = ""
Text1(2).Text = ""
If IsNull(objSWbemObject.DNSServerSearchOrder) Then
Text1(3).Text = ""
Else
Text1(3).Text = objSWbemObject.DNSServerSearchOrder(0)
End If
Else
Text1(0).Text = objSWbemObject.IPAddress(0)
Text1(1).Text = objSWbemObject.IPSubnet(0)
Text1(2).Text = objSWbemObject.DefaultIPGateway(0)
Text1(3).Text = objSWbemObject.DNSServerSearchOrder(0)
End If
Next
End Sub
'设置网卡的IP地址、子网掩码、缺省网关和DNS
Private Sub Command1_Click()
Set objSWbemObjectSet = objSWbemServices.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where Description='" & Combo1.Text & "'")
For Each objSWbemObject In objSWbemObjectSet
objSWbemObject.EnableStatic Array(Text1(0).Text), Array(Text1(1).Text)
objSWbemObject.SetGateways Array(Text1(2).Text)
objSWbemObject.SetDNSServerSearchOrder Array(Text1(3).Text)
Next
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
AiPPT
2024-09-19 广告
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询