InPowerS.Net

 找回密碼
 註冊
搜索
查看: 2266|回復: 0

透過 WMI 更改IP、子網路遮罩、閘道、DNS

[複製鏈接]
發表於 2008-12-26 13:07:43 | 顯示全部樓層 |閱讀模式
本帖最後由 肥龍 於 2008-12-26 13:09 編輯





Dim strWMIcls As String


Dim objNetAdt As Object




Dim strIPaddress As String, strSubMask As String, strGateway As String


Dim strDNS1 As String, strDNS2 As String




strWMIcls = "Win32_NetworkAdapterConfiguration" ' WMI
類別



strIPaddress = "192.168.10.99" ' IP
位址

strSubMask = "255.255.255.0" '
子網路遮罩

strGateway = "192.168.10.254"
'
預設閘道



strDNS1 = "168.95.1.1" '
慣用 DNS 伺服器

strDNS2 = "168.95.192.1" '
其他 DNS 伺服器



Set objNetAdt = GetObject("winmgmts:").InstancesOf(strWMIcls)(strWMIcls & ".Index=1")




' Index=1 , 1
是可變的 , 可為 1 ~ N



With objNetAdt




'
變更 IP Address

If .EnableStatic(Array(strIPaddress), Array(strSubMask)) = 0 Then MsgBox "IP
變更成功 !"



'
變更 Gateway

If .SetGateways(Array(strGateway), Array(1)) = 0 Then MsgBox "Gateway
變更成功 !"



'
變更 DNS Server

If .SetDNSServerSearchOrder(Array(strDNS1, strDNS2)) = 0 Then MsgBox "DNS
變更成功 !"



End With



[來源]http://blog.blueshop.com.tw/HammerChou/archive/2006/04/12/21368.aspx
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

小黑屋|Archiver|手機版|InPowerS.Net

GMT+8, 2025-5-9 13:05

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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