Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error "System.Management.ManagementObjectSearcher Is Not Defined" 1

Status
Not open for further replies.

IlyaRabyy

Programmer
Nov 9, 2010
566
0
16
US
Colleagues,
What worked in WinForms type of project ain't wanna work in the Service type project.
Picture worth 1,000 words, so:

2024-04-29_System_Management_ManagementObjectSearcher_Is_Not_Defined_mldo2i.jpg


As you can see, the System.Management is imported, but...

Here's the code:

Code:
'====================================================================================================================================
Public Function GetUserNames() As String
'====================================================================================================================================
Dim lsLogStr As String = ""

' Let's get digging! But keep in mind that if it's a network server, it might be unavailable, hence Try-Catch-EndTry construct.
Try
	Dim lcMachineName As String = "\\" + AddBackSlash(CharTran(gcMachineName, "\", ""))
	Dim loSearcher As New System.Management.ManagementObjectSearcher(lcMachineName + "root\cimv2", "SELECT * FROM Win32_ComputerSystem")
	Dim loQueryCollection As ManagementObjectCollection = loSearcher.Get()

	For Each loQueryObj As ManagementObject In loQueryCollection
		lsLogStr += loQueryObj("UserName").ToString() + vbCrLf
	Next
Catch loErr As Exception
	lsLogStr = Read_Exception(loErr)
	If Strings.Left(lsLogStr, 2) <> vbCrLf Then lsLogStr += vbCrLf
	My.Computer.FileSystem.WriteAllText(gsLogFile, lsLogStr, true)
End Try

Return lsLogStr

End Function
'====================================================================================================================================

What am I doing wrong?

AHWBGA!

Regards,

Ilya
 
How about this?

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top