2

I have a python script which extracts the hardware info of all my windows workstation in my network (for saying let it be client machines)

aim: to extract the hardware information of all the windows machines on the network.

my setup:

  • python version - 3.7x (32bit)
  • using wmi library to get the hardware info like serial number, system name.
  • client machine - 300+, under the same domain and same network(192.168.21.0 - 192.168.21.200).

the issue I faced: if I run my script with passing the remote IP address with local admin's credentials, actually how wmi library works.

Error :

Traceback (most recent call last):
  File "C:\Python3\lib\site-packages\wmi.py", line 1263, in connect       
    authentication_level=authentication_level
  File "C:\Python3\lib\site-packages\wmi.py", line 1397, in connect_server
    named_value_set
  File "<COMObject WbemScripting.SWbemLocator>", line 5, in ConnectServer 
  File "C:\Python3\lib\site-packages\win32com\client\dynamic.py", line 287, in _ApplyTypes_
    result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'SWbemLocator', 'Access is denied. ', None, 0, -2147024891), None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "j:/Projects/pythonProjects/networkassesttracker/matserbuild.py", line 3, in <module>
    con = wmi.WMI("192.168.225.117",user=r'admin',password='admin01')   #FILL WITH THE REMOTE MACHINE NAME
  File "C:\Python3\lib\site-packages\wmi.py", line 1290, in connect
    handle_com_error ()
  File "C:\Python3\lib\site-packages\wmi.py", line 241, in handle_com_error
    raise klass (com_error=err)
wmi.x_access_denied: <x_wmi: Unexpected COM Error (-2147352567, 'Exception occurred.', (0, 'SWbemLocator', 'Access is denied. ', None, 0, -2147024891), None)>

This wmi.x_access_denied can be overcome by enabling/changing these settings in each and every client machines, for testing purpose I checked and it worked, FYI this solution was giver by this blog WMI "access denied" error for remote computer

  1. Enabled Remote access for WMI user from WMI Control -> CIMV2

  2. enabled remote WMI through the firewall: netsh firewall set service RemoteAdmin enable

  3. changed DCOM Configuration in dcomcnfg for WMI user by give that account “Remote Activation” permission

I have 200+ clients, so I cant go and enable or change these settings manually for every node I have.

Is there any possible solution, like creating any domain user with wmi access or writing any group policy for all the domain computers?

My main goal: To extract hardware information like workstation serialNumber, workstation name, GPU name, Monitor serial number of remote machines (windows 7 & 10) which resides in my same network.

praveen
  • 179
  • 1
  • 3
  • 16

0 Answers0