Korne

Hello everybody.

I'm working on a project and I need to use WMI classes for some system informations

It works very well for differents classes but I have a problem with one of the class I need: Win32_NetworkConnection

I can't obtain the different informations in this class

(ConnectionType, ConnectionState, Status, ....)

I created a WMI class with only the informations I need:

Code Snippet

Imports System.Management

Public Class clsWMI

Private objOS As ManagementObjectSearcher

Private objCS As ManagementObjectSearcher

Private objNw 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

Private m_ConnectionState As String

Private m_ConnectionType As String

Private m_Status As String

Public Sub New()

objOS = New ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")

objCS = New ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem")

objNw = New ManagementObjectSearcher("SELECT * FROM Win32_NetworkConnection")

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

For Each objMgmt In objCS.Get

m_strManufacturer = objMgmt("manufacturer").ToString()

m_StrModel = objMgmt("model").ToString()

m_strSystemType = objMgmt("systemtype").ToString

m_strTPM = objMgmt("totalphysicalmemory").ToString()

Next

For Each objMgmt In objNw.Get

m_ConnectionState = objMgmt("connectionState").ToString()

m_ConnectionType = objMgmt("connectionType").ToString()

m_Status = objMgmt("status").ToString

Next

End Sub

Public ReadOnly Property ComputerName()

Get

ComputerName = m_strComputerName

End Get

End Property

Public ReadOnly Property Manufacturer()

Get

Manufacturer = m_strManufacturer

End Get

End Property

Public ReadOnly Property Model()

Get

Model = m_StrModel

End Get

End Property

Public ReadOnly Property OsName()

Get

OsName = m_strOSName

End Get

End Property

Public ReadOnly Property OSVersion()

Get

OSVersion = m_strOSVersion

End Get

End Property

Public ReadOnly Property SystemType()

Get

SystemType = m_strSystemType

End Get

End Property

Public ReadOnly Property TotalPhysicalMemory()

Get

TotalPhysicalMemory = m_strTPM

End Get

End Property

Public ReadOnly Property WindowsDirectory()

Get

WindowsDirectory = m_strWindowsDir

End Get

End Property

Public ReadOnly Property ConnectionState()

Get

ConnectionState = m_ConnectionState

End Get

End Property

Public ReadOnly Property ConnectionType()

Get

ConnectionType = m_ConnectionType

End Get

End Property

Public ReadOnly Property Status()

Get

Status = m_Status

End Get

End Property

End Class

And I use my class with this code:

Code Snippet

Dim objWMI As New clsWMI()

With objWMI

txtResultSearch.Text = "Computer Name = " & .ComputerName & Chr(13) & Chr(10)

txtResultSearch.Text += "Computer Manufacturer = " & .Manufacturer & Chr(13) & Chr(10)

txtResultSearch.Text += "Computer Model = " & .Model & Chr(13) & Chr(10)

txtResultSearch.Text += "OS Name = " & .OsName & Chr(13) & Chr(10)

txtResultSearch.Text += "OS Version = " & .OSVersion & Chr(13) & Chr(10)

txtResultSearch.Text += "System Type = " & .SystemType & Chr(13) & Chr(10)

txtResultSearch.Text += "Total Physical Memory = " & .TotalPhysicalMemory & Chr(13) & Chr(10)

txtResultSearch.Text += "Windows Directory = " & .WindowsDirectory & Chr(13) & Chr(10)

txtResultSearch.Text += "ConnectionType = " & .ConnectionType & Chr(13) & Chr(10)

txtResultSearch.Text += "ConnectionState = " & .ConnectionState & Chr(13) & Chr(10)

txtResultSearch.Text += "Status = " & .Status

End With

The 8 first parameters work very well (Win32_OperatingSystem and Win32_ComputerSystem WMI classes)

But the 3 last parameters doesn't work and I don't know why Can we use tle WMI class Win32_NetworkConnection

Thank you very much for your help.

Best regards.



Re: Visual Basic Express Edition problems to use WMI classes with VB 2005 express.

Korne

Hello everybody.

I'm working on a project and I need to use WMI classes for some system informations

It works very well for differents classes but I have a problem with one of the class I need: Win32_NetworkConnection

I can't obtain the different informations in this class

(ConnectionType, ConnectionState, Status, ....)

I created a WMI class with only the informations I need:

Code Snippet

Imports System.Management

Public Class clsWMI

Private objOS As ManagementObjectSearcher

Private objCS As ManagementObjectSearcher

Private objNw 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

Private m_ConnectionState As String

Private m_ConnectionType As String

Private m_Status As String

Public Sub New()

objOS = New ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")

objCS = New ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem")

objNw = New ManagementObjectSearcher("SELECT * FROM Win32_NetworkConnection")

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

For Each objMgmt In objCS.Get

m_strManufacturer = objMgmt("manufacturer").ToString()

m_StrModel = objMgmt("model").ToString()

m_strSystemType = objMgmt("systemtype").ToString

m_strTPM = objMgmt("totalphysicalmemory").ToString()

Next

For Each objMgmt In objNw.Get

m_ConnectionState = objMgmt("connectionState").ToString()

m_ConnectionType = objMgmt("connectionType").ToString()

m_Status = objMgmt("status").ToString

Next

End Sub

Public ReadOnly Property ComputerName()

Get

ComputerName = m_strComputerName

End Get

End Property

Public ReadOnly Property Manufacturer()

Get

Manufacturer = m_strManufacturer

End Get

End Property

Public ReadOnly Property Model()

Get

Model = m_StrModel

End Get

End Property

Public ReadOnly Property OsName()

Get

OsName = m_strOSName

End Get

End Property

Public ReadOnly Property OSVersion()

Get

OSVersion = m_strOSVersion

End Get

End Property

Public ReadOnly Property SystemType()

Get

SystemType = m_strSystemType

End Get

End Property

Public ReadOnly Property TotalPhysicalMemory()

Get

TotalPhysicalMemory = m_strTPM

End Get

End Property

Public ReadOnly Property WindowsDirectory()

Get

WindowsDirectory = m_strWindowsDir

End Get

End Property

Public ReadOnly Property ConnectionState()

Get

ConnectionState = m_ConnectionState

End Get

End Property

Public ReadOnly Property ConnectionType()

Get

ConnectionType = m_ConnectionType

End Get

End Property

Public ReadOnly Property Status()

Get

Status = m_Status

End Get

End Property

End Class

And I use my class with this code:

Code Snippet

Dim objWMI As New clsWMI()

With objWMI

txtResultSearch.Text = "Computer Name = " & .ComputerName & Chr(13) & Chr(10)

txtResultSearch.Text += "Computer Manufacturer = " & .Manufacturer & Chr(13) & Chr(10)

txtResultSearch.Text += "Computer Model = " & .Model & Chr(13) & Chr(10)

txtResultSearch.Text += "OS Name = " & .OsName & Chr(13) & Chr(10)

txtResultSearch.Text += "OS Version = " & .OSVersion & Chr(13) & Chr(10)

txtResultSearch.Text += "System Type = " & .SystemType & Chr(13) & Chr(10)

txtResultSearch.Text += "Total Physical Memory = " & .TotalPhysicalMemory & Chr(13) & Chr(10)

txtResultSearch.Text += "Windows Directory = " & .WindowsDirectory & Chr(13) & Chr(10)

txtResultSearch.Text += "ConnectionType = " & .ConnectionType & Chr(13) & Chr(10)

txtResultSearch.Text += "ConnectionState = " & .ConnectionState & Chr(13) & Chr(10)

txtResultSearch.Text += "Status = " & .Status

End With

The 8 first parameters work very well (Win32_OperatingSystem and Win32_ComputerSystem WMI classes)

But the 3 last parameters doesn't work and I don't know why Can we use tle WMI class Win32_NetworkConnection

Thank you very much for your help.

Best regards.





Re: Visual Basic Express Edition problems to use WMI classes with VB 2005 express.

kleinma

what OS are you running I tested your code on WinXP sp2, and it worked fine to get the Win32_NetworkConnection WMI info...

Also you should really consider running with Option Strict On..






Re: Visual Basic Express Edition problems to use WMI classes with VB 2005 express.

Korne

True. I forgot the Option Strict on.

I work on WinXP sp2 too.

Thank you.





Re: Visual Basic Express Edition problems to use WMI classes with VB 2005 express.

Korne

I tried this

Code Snippet

Option Strict On

Option Explicit On

Imports System.Management

Public Class clsWMI

End Class

It doesn't work. I don't know why. I'm working on winXP sp2.




Re: Visual Basic Express Edition problems to use WMI classes with VB 2005 express.

kleinma

do you have a second machine you can run your code against, because again, i copied/pasted your code (even left option strict off) and I was able to query the data you say you are having trouble with.




Re: Visual Basic Express Edition problems to use WMI classes with VB 2005 express.

Korne

No I tried on only one computer.

It's strange because it works with some classes and it doesn't work with some other classes.

Is it possible that it doesn't work beacause of my CPUs I have 2 AMD 64 x2 DUAL.

I don't know I'm searching.

Thank you.





Re: Visual Basic Express Edition problems to use WMI classes with VB 2005 express.

kleinma

I don't know why having 2 CPUs would have anything to do with querying network information.

I only have 1 CPU, but it is a dual core, so Windows thinks I have 2 (my guess is windows thinks you have 4 if you have 2 dual core CPUs)

I would suggest you try it on another machine first...






Re: Visual Basic Express Edition problems to use WMI classes with VB 2005 express.

Korne

Yes I will try.

But I developped my project on this computer.

Do you mean that It will be impossible to continue on this computer

WMI classes is a key point in my project Sad

Have you any idea why I can't query this informations

Thank you for your help.





Re: Visual Basic Express Edition problems to use WMI classes with VB 2005 express.

kleinma

no I just want you to try it on another machine to try to narrow things down and get to the root of the problem.

Maybe something is just corrupt or wrong with WMI on your given machine. If you run it on another machine, and it works fine, then you can at least isolate the problem to the specific computer, and not your code.


Then from there you can try to figure out why WMI is not working correctly for certain things on your machine.






Re: Visual Basic Express Edition problems to use WMI classes with VB 2005 express.

kleinma

Here is a link to a WMI diagnostic utility from Microsoft

http://www.microsoft.com/downloads/details.aspx familyid=d7ba3cd6-18d1-4d05-b11e-4c64192ae97d&displaylang=en

Here is a link on how to repair WMI if needed

http://windowsxp.mvps.org/repairwmi.htm






Re: Visual Basic Express Edition problems to use WMI classes with VB 2005 express.

Korne

Thank you for your help.

I will try tonight at my home on my own computer. It works on winXP sp2 too so I hope I will see what is the problem.





Re: Visual Basic Express Edition problems to use WMI classes with VB 2005 express.

Korne

I tried last night on my computer at home and it works very well.

I don't understand why I doesn't work on this computer.

I will try to repair the WMI Repository.





Re: Visual Basic Express Edition problems to use WMI classes with VB 2005 express.

Korne

Hi everybody.

I still have my problem and I used the wbemtest.exe in windows/system32/wbem.

I tried to create a query to test the class (select * from Win32_NetworkConnection) and there was no result.

I don't know why. When I test with an another class (Win32_UserAccount for exemple) and it works well.

Strange thing .....





Re: Visual Basic Express Edition problems to use WMI classes with VB 2005 express.

kleinma

even after the repair you still get nothing