Colleagues,
What worked in WinForms type of project ain't wanna work in the Service type project.
Picture worth 1,000 words, so:
As you can see, the System.Management is imported, but...
Here's the code:
What am I doing wrong?
AHWBGA!
Regards,
Ilya
What worked in WinForms type of project ain't wanna work in the Service type project.
Picture worth 1,000 words, so:
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