1月15

IP设置

| |
21:38V B 源码  From: 本站原创

Option Explicit
Dim objSWbemServices As SWbemServices
Dim objSWbemObjectSet As SWbemObjectSet
Dim objSWbemObject As SWbemObject
Function WMIDateToString(dtmDate)

WMIDateToString = CDate(Mid(dtmDate, 5, 2) & "/" & _
                 Mid(dtmDate, 7, 2) & "/" & _
                 Left(dtmDate, 4) & " " & _
                 Mid(dtmDate, 9, 2) & ":" & _
                 Mid(dtmDate, 11, 2) & ":" & _
                 Mid(dtmDate, 13, 2))

End Function
[separator]
Private Sub Command4_Click()
Set objSWbemObjectSet = objSWbemServices.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where Description='" & Combo1.Text & "'")
   For Each objSWbemObject In objSWbemObjectSet
       objSWbemObject.RenewDHCPLease
           Next
   MsgBox "续定IP成功!", 64, "信息"
           Call Combo1_Click

End Sub

Private Sub Command5_Click()
Set objSWbemObjectSet = objSWbemServices.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where Description='" & Combo1.Text & "'")
   For Each objSWbemObject In objSWbemObjectSet
       objSWbemObject.ReleaseDHCPLease
     
       Next
     MsgBox "释放IP成功!", 64, "信息"
           Call Combo1_Click
End Sub

Private Sub Command6_Click()
Set objSWbemObjectSet = objSWbemServices.ExecQuery("Select * From Win32_NetworkAdapter Where Description='" & Combo1.Text & "'")
   For Each objSWbemObject In objSWbemObjectSet
   objSWbemObject.EnableNetConnectionID
Next

End Sub

'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)
   If Combo1 = "" Then
   Exit Sub
   Else
 
   Combo1.ListIndex = 0
   End If
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
       Text1(0).Text = objSWbemObject.IPAddress(0)
       Text1(1).Text = objSWbemObject.IPSubnet(0)
   If IsNull(objSWbemObject.DNSServerSearchOrder) Then
               Text1(3).Text = ""
               Text1(4).Text = ""
           Else
               Text1(3).Text = objSWbemObject.DNSServerSearchOrder(0)
               Text1(4).Text = objSWbemObject.DNSServerSearchOrder(1)
           End If
    If IsNull(objSWbemObject.DefaultIPGateway) Then
               Text1(2).Text = ""
           Else
               Text1(2).Text = objSWbemObject.DefaultIPGateway(0)
           End If
       If IsNull(objSWbemObject.DHCPLeaseObtained) Then
            Text1(5).Text = ""
           Text1(6).Text = ""
           Else
           Text1(5).Text = WMIDateToString(objSWbemObject.DHCPLeaseObtained)
           Text1(6).Text = WMIDateToString(objSWbemObject.DHCPLeaseExpires)
           End If
               If IsNull(objSWbemObject.DHCPServer) Then
               Text1(7).Text = ""
               Else
           Text1(7).Text = objSWbemObject.DHCPServer
           End If
           Text1(8) = objSWbemObject.macAddress
                   
        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, Text1(4).Text)
   Next
    MsgBox "网卡参数设置成功!", 64, "信息"
End Sub

Private Sub Command2_Click()
   Unload Me
End Sub
Private Sub Command3_Click()

   Set objSWbemObjectSet = objSWbemServices.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where Description='" & Combo1.Text & "'")
   For Each objSWbemObject In objSWbemObjectSet
       objSWbemObject.EnableDHCP
       objSWbemObject.SetDNSServerSearchOrder
       Next
     MsgBox "恢复自动获取IP成功!", 64, "信息"
End Sub


来源:夕阳醉了's Blog
地址:http://oznn.com/post/4/
转载时须以链接形式注明作者和原始出处及本声明!
阅读(3193) | 评论(0) | 引用(0)
发表评论
表情
emotemotemotemot
emotemotemotemot
emotemotemotemot
emotemotemotemot
emotemotemotemot
emotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]