Converting an old WSH function to VB.NET...

Halonix

Member
Joined
Aug 7, 2004
Messages
8
Programming Experience
3-5
Im trying to convert the following function to vb.net. This was origionally in a wsh script and was working fine. The problem mainly is that .NET no longer supports the Eval method. To describe the function a little: When called it is passed a wmi class name to check ie "Win32_System" and a property ie "Computername" it then executes a wmi query on the machine to get the information. And returns it in a comma seperated string. The purpose of the Eval statement is to allow the property to be specified dynamically. Any ideas on what I could use to replace that Eval statement?

VB.NET:
     Private Function GetSystemInfo(strWMIClass,strProperty)
	
	counter = 0
	Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & SystemPath & "\root\cimv2")
	Set colProc = objWMIService.ExecQuery ("Select * from " &  strWMIClass)
	For each prop in colProc
		HardwareValue = HardwareValue & Eval("prop." & strProperty ) & ","
	Next
	If HardwareValue <> "" Then
		GetSystemInfo = Mid(HardwareValue,1,Len(HArdwareValue)-1) 'Trim off trailing comma	
	Else
		GetSystemInfo = 0
	End If

     End Function
 
Sorry, I can't help with a replacement for the Eval function, but if you want to get the computer name (or other info in the environment-string table), use the Microsoft.VisualBasic.Interaction.Environ function, eg.: Environ("ComputerName").
 
Paszt said:
Sorry, I can't help with a replacement for the Eval function, but if you want to get the computer name (or other info in the environment-string table), use the Microsoft.VisualBasic.Interaction.Environ function, eg.: Environ("ComputerName").
This function is supposed to be able to work on a remote machine using WMI. So I guess what Im trying to do here is find someway to interface with WMI in .net to allow me to specify the correct property dynamically.
 
Back
Top