title: Get Operating System Info from a network host (LAN connected PC)
body: <p>I am trying to get information from host connected to local network. Following code give operating system name like <strong><em>Microsoft Windows 10 Pro</em></strong> in my local pc. When I use a network pc name then prompt error <code>Access Denied</code></p>
  
  <p><a href="https://i.stack.imgur.com/qwsxS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qwsxS.png" alt="enter image description here"></a></p>
  
  <p>My understanding is, it is not getting permission to collect information from that PC because there is no credential provided. So, my question is how to provide credential to these codes so that it can get permission to collect.</p>
  
  <blockquote>
    <p>Note: I have added exception <code>Windows Management Instrumentation (WMI)</code> to windows firewall on remote PC.</p>
  </blockquote>
  
  <pre><code>Sub GetOS()
      If getOperatingSystem &lt;&gt; "" Then
          MsgBox getOperatingSystem()
      End If
  End Sub
  
  '------------- Function to get Operating System Info --------------
  
  Public Function getOperatingSystem()
      Dim localHost       As String
      Dim objWMIService   As Variant
      Dim colOperatingSystems As Variant
      Dim objOperatingSystem As Variant
  
      On Error GoTo Error_Handler
  
      'localHost = "." 'Technically could be run against remote computers, if allowed
      localHost = "SCANNER-PC"
      Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &amp; localHost &amp; "\root\cimv2")
      Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
      For Each objOperatingSystem In colOperatingSystems
          getOperatingSystem = objOperatingSystem.Caption '&amp; " " &amp; objOperatingSystem.Version
          Exit Function
      Next
  
  Error_Handler_Exit:
      On Error Resume Next
      Exit Function
  
  Error_Handler:
      MsgBox "Error No: " &amp; Err.Number &amp; vbCrLf &amp; "Description: " &amp; Err.Description
      Resume Error_Handler_Exit
  End Function
  </code></pre>