2013-10-22 75 views
-1

我嘗試創建visual basic 2010程序,用於檢測連接了哪個連接及其ip地址。例如,如果我使用無線和有線連接,它將顯示媒體連接和它的IP地址。這從WMI代碼創建者使用visual basic 2010顯示連接狀態

Dim strComputer = "." 
Dim Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery(_ 
"SELECT * FROM Win32_NetworkAdapterConfiguration",,48) 
For Each objItem in colItems 
Wscript.Echo "-----------------------------------" 
Wscript.Echo "Win32_NetworkAdapterConfiguration instance" 
Wscript.Echo "-----------------------------------" 
If isNull(objItem.IPAddress) Then 
    Wscript.Echo "IPAddress: " 
Else 
    Wscript.Echo "IPAddress: " & Join(objItem.IPAddress, ",") 
End If 

碼我把後來,我被錯誤信息

'colItems' is not declared. It may be inaccessible due to its protection level. 

我是錯在做什麼?有人可以告訴我,如果這是錯誤的代碼或不?

+0

'我是做錯誤的'也就是說VBScript中,不VB.NET。 – ElektroStudios

回答

0

更好地使用類ManagementObjectSearcher。下面一個例子:

Private objOS As ManagementObjectSearcher 
Private objCS As ManagementObjectSearcher 
Private objMgmt As ManagementObject 
Private m_strComputerName As String 
Private m_strManufacturer As String 
Private m_StrModel As String 
Private m_strOSName As String 
Private m_strOSVersion As String 
Private m_strSystemType As String 
Private m_strTPM As String 
Private m_strWindowsDir As String 


Public Sub New() 

    objOS = New ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem") 
    objCS = New ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem") 
    For Each objMgmt In objOS.Get 


     m_strOSName = objMgmt("name").ToString() 
     m_strOSVersion = objMgmt("version").ToString() 
     m_strComputerName = objMgmt("csname").ToString() 
     m_strWindowsDir = objMgmt("windowsdirectory").ToString() 
    Next 

查詢只需更改爲:SELECT * FROM Win32_NetworkAdapterConfiguration