hakril / PythonForWindows

A codebase aimed to make interaction with Windows and native execution easier
BSD 3-Clause "New" or "Revised" License
573 stars 112 forks source link

curious question about querying AD/WMI over the network #39

Closed commandline-be closed 2 years ago

commandline-be commented 2 years ago

Hey

Looking to query an AD over the LAN i'm curious if PythonForWindows supports this. The idea is to query installed software, users and their privileges for data colletion and then parse this data into an excel.

br,

JL

hakril commented 2 years ago

Hi,

PythonForWindows should be able to connect/query other computers of the domain via WMI (as is is a capability of WMI). I, myself, have never tested this feature but you should be able to try using something like the following snippet :

import windows
windows.com.init()
# https://docs.microsoft.com/en-us/windows/win32/api/wbemcli/nf-wbemcli-iwbemlocator-connectserver
namespace = windows.winobject.wmi.WmiNamespace.connect(r"\TARGET_SRV\root\cimv2", user=username, password=password)
print(namespace.select("Win32_Process"))

I guess you might not need a user/password if you use a privileged account of the domain but I am not sure. If you test this, I would take any feedback about how it worked for you or not as I never tried that on a domain.

Thank you,