[python-win32] Need a value from pywin32

Tim Roberts timr at probo.com
Wed Jun 22 01:04:17 EDT 2022


On 6/21/22 13:39, Steven Manross wrote:

> I was intrigued by this and I would like to get it to work, but I cannot...  I know I'm doing something wrong, but don't know what.  I will leave this for the archives, and maybe it will help someone else some day.
> ...
> def get_wts_info(session_id):
>      '''
>          Get WTS Info
>      '''
>      # This only tries to work on the local server currently but I get an access violation running the WinStationQueryInformationW line
>
>      Buf = ctypes.POINTER(WinStationInformation)()
>      BufLen = 260
>
>      hWinSta = ctypes.windll.LoadLibrary("WINSTA.DLL")
>      if hWinSta:
>          winsta_handle = hWinSta._handle
>          print(f'winsta_handle = {winsta_handle}')
>          QueryInfoHandle = ctypes.windll.kernel32.GetProcAddress(ctypes.c_ulonglong(winsta_handle), b"WinStationQueryInformationW")
>
>          # This handle is 0...  possibly because of the numeric conversion from the winsta_handle to a ctypes.c_ulonglong  ???  unsure

No, 0 is the error return that means the name was not found.

You shouldn't need to use LoadLibrary and GetProcAddress.  ctypes does 
that for you automatically.

     winsta = ctypes.WinDLL('winsta.dll')

     winsta.WinStationQueryInformationW( 0, session_id, 8, 
ctypes.byref(Buf), BufLen, ctypes.byref(RtnLen))

If you have Visual Studio, you can try doing "link /dump /exports 
\windows\system32\winsta.dll" to make sure it has that entry point.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list