[python-win32] WMI and Terminal Services

Mike Driscoll mdriscoll at co.marshall.ia.us
Fri Mar 25 19:19:48 CET 2011


Hi,

I am looking for a way to query the client name parameter from Terminal 
Services. I have been testing several scripts I've found that use either 
win32com.client or win32ts, but they are giving me weird errors on 
Windows 7 64-bit.

I get this traceback:

<traceback>

Traceback (most recent call last):
   File "\\server\loginscript$\getTSInfo.py", line 10, in ?
     for objItem in colItems:
   File 
"\\server\loginscript$\Python24\lib\site-packages\win32com\client\util.
py", line 84, in next
     return _get_good_object_(self._iter_.next(), resultCLSID = 
self.resultCLSID)

pywintypes.com_error: (-2147217392, 'OLE error 0x80041010', None, None)
</traceback>

When I run this:

<code>
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
colItems = objSWbemServices.ExecQuery("Select * from Win32_TSClientSetting")
for objItem in colItems:   # this is line 10
     # code snipped
</code>

If I try running this code instead:

<code>
server = win32ts.WTSOpenServer(".")
print "server info >> ",
print server
print "-" * 80

for s in win32ts.WTSEnumerateSessions(server, 1):
       if s['State'] == win32ts.WTSActive:
           print s
           session = s
</code>

I get this:

<traceback>

Traceback (most recent call last):
   File "\\debianis\loginscript$\getTSInfo.py", line 34, in ?
     for s in win32ts.WTSEnumerateSessions(server, 1):
pywintypes.error: (5, 'WTSEnumerateSessions', 'Access is denied.')

</traceback>

I'm assuming that this must be an incorrect way of accessing Telnet 
information on 64-bit Windows since it works on 32-bit. I never did 
figure out how to return the client name though except via the "os" 
module, like this: os.getenv("CLIENTNAME")

Is there a way to get it and other Terminal Services session information 
via these methods or WMI? Thanks!

-- 
Mike Driscoll
Applications Specialist



More information about the python-win32 mailing list