微剋多資訊

 找回密碼
 註冊

Sign in with google

Google帳號登入

搜索

該用戶從未簽到

升級   0%

跳轉到指定樓層
主題
發表於 2013-2-27 16:22 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
本帖最後由 rictirse 於 2014-5-22 22:03 編輯
  1. #include <GuiConstantsEx.au3>
  2. #include <GuiIPAddress.au3>
  3. #include <WindowsConstants.au3>
  4. #include <Array.au3>

  5. Opt ( "GUIOnEventMode", 1)

  6. Dim $Cnt = 5
  7. Dim $hIPAddress[$Cnt]
  8. Dim $Test[$Cnt] = [ "IP Address", "Subnet Mask", "GateWay", "DNS 1", "DNS 2"]
  9. Dim $ini = @ScriptDir&"IPList.ini"

  10. $hgui = GUICreate ( " IP Switch", 195, 240, Default, Default, 1)

  11. GUISetOnEvent ( $GUI_EVENT_CLOSE, "_Exit")

  12. For $i = 0 To ($Cnt-1)
  13.   GUICtrlCreateLabel ( $Test[$i], 10, 24+($i*30), 65)
  14.   $hIPAddress[$i] = _GUICtrlIpAddress_Create ( $hgui, 75, 20+($i*30), 100, 20)
  15.   _GUICtrlIpAddress_Set ( $hIPAddress[$i], IniRead ( $ini, "IP Address", "IP_Address"&$i, ""))
  16. Next

  17. GUICtrlCreateButton ( "Start", 30, 175, 60,25)
  18.   GUICtrlSetOnEvent ( -1, "_Start")

  19. GUICtrlCreateButton ( "Exit", 100, 175, 60,25)
  20.   GUICtrlSetOnEvent ( -1, "_Exit")

  21. GUISetState ()

  22. While True
  23.   For $i = 0 To ($Cnt-1)
  24.     _Save( $hIPAddress[$i], "IP_Address"&$i)
  25.   Next
  26.   Sleep (50)
  27. WEnd

  28. Func _Save($hIPAddress, $iniName)
  29.   $ipData = _GUICtrlIpAddress_Get($hIPAddress)
  30.   If $ipData = 0 Then Return

  31.   If $ipData <> IniRead ( $ini, "IP Address", $iniName, "") Then

  32.     IniWrite ( $ini, "IP Address", $iniName, $ipData)
  33.   EndIf
  34. EndFunc

  35. Func _Start()
  36.   Local $InterFace="區域連線"
  37.   Local $IPX = '00004444'

  38.   Local $IpADD = _GUICtrlIpAddress_Get($hIPAddress[0])
  39.   Local $SubMask = _GUICtrlIpAddress_Get($hIPAddress[1])
  40.   Local $GateWay = _GUICtrlIpAddress_Get($hIPAddress[2])
  41.   Local $DNS1 = _GUICtrlIpAddress_Get($hIPAddress[3])
  42.   Local $DNS2 = _GUICtrlIpAddress_Get($hIPAddress[4])

  43.   _WMI_SetNetworkAdapterInfo( $InterFace, $IpADD, $SubMask, $GateWay, $DNS1, $DNS2, $IPX)

  44.   MsgBox ( 0, "", "完成")
  45. EndFunc

  46. Func _Exit()
  47.   Exit
  48. EndFunc

  49. Func _WMI_SetNetworkAdapterInfo($HostName, $IpADD, $SubMask, $GateWay, $DNS1, $DNS2, $IPX)
  50.   Dim $SetDns[2], $SetIPAddress[1], $SetSubnetmask[1], $SetGateway[1]
  51.   $SetDns[0] = $DNS1
  52.   $SetDns[1] = $DNS2
  53.   $SetIPAddress[0] = $IpADD
  54.   $SetSubnetmask[0] = $SubMask
  55.   $SetGateway[0] = $GateWay
  56.   Local $objWMIService = ObjGet("winmgmts:\localhostrootCIMV2")
  57.   Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL", 0x10 + 0x20)
  58.   Local $colComputers = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
  59.   Local $objNetworkSettings = $objWMIService.Get("Win32_NetworkAdapterConfiguration")
  60.   For $objNetAdapter In $colComputers
  61.     $objNetAdapter.Rename($HostName)

  62.   Next
  63.   If IsObj($colItems) Then
  64.     For $objNetAdapter In $colItems
  65.       $objNetAdapter.EnableStatic($SetIPAddress, $SetSubnetmask)
  66.       $objNetAdapter.SetGateways($SetGateway)
  67.       $objNetAdapter.SetDNSServerSearchOrder($SetDns)
  68.     Next
  69.   EndIf
  70.   $objNetworkSettings.SetIPXVirtualNetworkNumber($IPX)
  71. EndFunc
複製代碼

本帖子中包含更多資源

您需要 登入 才可以下載或查看,沒有帳號?註冊

x
樓主熱門主題
您需要登入後才可以回帖 登入 | 註冊

本版積分規則

小黑屋|Archiver|微剋多資訊(MicroDuo)

GMT+8, 2024-11-23 17:31

Discuz! X

© 2009-2023 Microduo

快速回覆 返回頂部 返回列表