Hello,
I have a Function that returns the Operating system that is running on a computer. This code works well for me and numerous other people, but there is 1 person that when they run this code they get an error.
The error that this individual encounters is on the line:
"Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & localHost & "\root\cimv2")"
I think it might have something to do with my variable "localHost", but I'm not totally sure. I'm hoping somebody else has encountered this problem before.
Thanks in advance.
I have a Function that returns the Operating system that is running on a computer. This code works well for me and numerous other people, but there is 1 person that when they run this code they get an error.
The error that this individual encounters is on the line:
"Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & localHost & "\root\cimv2")"
I think it might have something to do with my variable "localHost", but I'm not totally sure. I'm hoping somebody else has encountered this problem before.
Code:
Public Function getOperatingSystem()
Dim localHost As String, objWMIService As Variant, colOperatingSystems As Variant
Dim objOperatingSystem As Variant
localHost = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & localHost & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objOperatingSystem In colOperatingSystems
getOperatingSystem = objOperatingSystem.Caption ' & " " & objOperatingSystem.version
Exit Function
Next
End Function
Thanks in advance.