K
K
Konstantin Gorodetsky2015-04-13 14:55:07
Python
Konstantin Gorodetsky, 2015-04-13 14:55:07

One element must be selected. How to do without a cycle?

I'm trying to extract the login of the user who is currently working for the PC hostname

import wmi
wmiConn = wmi.WMI(hostname)
for cs in wmiConn.Win32_ComputerSystem():
    curUser = cs.UserName
Why in this case it is impossible to write: curUser = wmiConn.Win32_ComputerSystem().UserName ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
lPolar, 2015-04-13
@gorodetskiykp

Why can't you select an element by index?

import wmi
wmiConn = wmi.WMI(hostname)
curUser = wmiConn.Win32_ComputerSystem()[0].UserName

V
Vadim Shandrinov, 2015-04-13
@suguby

Well, probably because Win32_ComputerSystem returns a list...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question