I'm trying to get the user logged into a computer on the network.
computer = wmi.WMI('10.1.11.55')
for us in computer.Win32_LogonSession():
for user in us.references("Win32_LoggedOnUser"):
print(user.Antecedent.Name)
When I run the above code, an exception is thrown.
I am also an admin user on the remote host.
Traceback (most recent call last):
File "C:\Users\231527\Documents\GitHub\pygetip\venv\lib\site-packages\wmi.py", line 1311, in connect
obj = GetObject(moniker)
File "C:\Users\231527\Documents\GitHub\pygetip\venv\lib\site-packages\win32com\client__init.py", line 86, in GetObject
return Moniker(Pathname, clsctx)
File "C:\Users\231527\Documents\GitHub\pygetip\venv\lib\site-packages\win32com\client__init__.py", line 103, in Moniker
moniker, i, bindCtx = pythoncom.MkParseDisplayName(Pathname)
pywintypes.com_error: (-2147217406, 'OLE error 0x80041002', None, None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2022.3.2\plugins\python-ce\helpers\pydev\pydevconsole.py", line 364, in runcode
coro = func()
File "", line 3, in
File "C:\Users\231527\Documents\GitHub\pygetip\venv\lib\site-packages\wmi.py", line 597, in getattr__
return WMI(moniker=value)
File "C:\Users\231527\Documents\GitHub\pygetip\venv\lib\site-packages\wmi.py", line 1354, in connect
handle_com_error()
File "C:\Users\231527\Documents\GitHub\pygetip\venv\lib\site-packages\wmi.py", line 258, in handle_com_error
raise klass(com_error=err)
wmi.x_wmi: <x_wmi: Unexpected COM Error (-2147217406, 'OLE error 0x80041002', None, None)>
Hi.
I'm trying to get the user logged into a computer on the network.
When I run the above code, an exception is thrown.
I am also an admin user on the remote host.
Traceback (most recent call last): File "C:\Users\231527\Documents\GitHub\pygetip\venv\lib\site-packages\wmi.py", line 1311, in connect obj = GetObject(moniker) File "C:\Users\231527\Documents\GitHub\pygetip\venv\lib\site-packages\win32com\client__init.py", line 86, in GetObject return Moniker(Pathname, clsctx) File "C:\Users\231527\Documents\GitHub\pygetip\venv\lib\site-packages\win32com\client__init__.py", line 103, in Moniker moniker, i, bindCtx = pythoncom.MkParseDisplayName(Pathname) pywintypes.com_error: (-2147217406, 'OLE error 0x80041002', None, None) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2022.3.2\plugins\python-ce\helpers\pydev\pydevconsole.py", line 364, in runcode coro = func() File "", line 3, in
File "C:\Users\231527\Documents\GitHub\pygetip\venv\lib\site-packages\wmi.py", line 597, in getattr__
return WMI(moniker=value)
File "C:\Users\231527\Documents\GitHub\pygetip\venv\lib\site-packages\wmi.py", line 1354, in connect
handle_com_error()
File "C:\Users\231527\Documents\GitHub\pygetip\venv\lib\site-packages\wmi.py", line 258, in handle_com_error
raise klass(com_error=err)
wmi.x_wmi: <x_wmi: Unexpected COM Error (-2147217406, 'OLE error 0x80041002', None, None)>