Sign in to follow this  
Followers 0
Yogui

WTSEnumerateSessions API in AUTOIT ?

4 posts in this topic




Hello

can you help me to use this API : WTSEnumerateSessions

http://msdn.microsoft.com/en-us/library/aa383833(VS.85).aspx

I would like to get back the name of the TSE

Merci

Look at the DllCall() and DllStruct* functions in the help file. If you are not very familiar with DLL calls then the parameters are likely to stump you:

ppSessionInfo [out]

Pointer to a variable that receives a pointer to an array of WTS_SESSION_INFO structures. Each structure in the array contains information about a session on the specified terminal server. To free the returned buffer, call the WTSFreeMemory function.

To be able to enumerate a session, you need to have the Query Information permission. For more information, see Terminal Services Permissions. To modify permissions on a session, use the Terminal Services Configuration administrative tool.

pCount [out]

Pointer to the variable that receives the number of WTS_SESSION_INFO structures returned in the ppSessionInfo buffer.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Ok. PSaltyDS - You are Right.... I am stumped on the DLL calls...

Does anyone have a working example that returns the number of Terminal Server Sessions?

----------------

DllOpen("Wtsapi32.dll")

The Function in the DLL that I want to use is WTSEnumerateSessions (or WTSEnumerateSessionsEx)

The Parameters for WTSEnumberateSessions are below hServer [in]

A handle to an RD Session Host server. Specify a handle opened by the WTSOpenServer or WTSOpenServerEx function, or specify WTS_CURRENT_SERVER_HANDLE to indicate the RD Session Host server on which your application is running. Reserved [in]

This parameter is reserved. It must be zero. Version [in]

The version of the enumeration request. This parameter must be 1. ppSessionInfo [out]

A pointer to a variable that receives a pointer to an array of WTS_SESSION_INFO structures. Each structure in the array contains information about a session on the specified RD Session Host server. To free the returned buffer, call the WTSFreeMemory function.

To enumerate a session, you must have Query Information permission. For more information, see Remote Desktop Services Permissions. To modify permissions on a session, use the Remote Desktop Services Configuration administrative tool.

To enumerate sessions running on a virtual machine hosted on a RD Virtualization Host server, you must be a member of the Administrators group on the RD Virtualization Host server. pCount [out]

A pointer to the variable that receives the number of WTS_SESSION_INFO structures returned in the ppSessionInfo buffer.

I think I need to build a structure to access only pCount when using DllStructGetData?

Edited by ZipleR

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I just created this using WMI and it seems to work on Windows 7 and Server 2008. It does not work on Server 2003.

Dim $result$

WMI = ObjGet("winmgmts:" & @ComputerName & "rootcimv2") ;connect to WMI on computer
$query = $WMI.ExecQuery("SELECT * FROM Win32_TerminalService") ;query remote machine

For $element in $query
     $result = "Sesstions:" & $element.TotalSessions -2 & Chr(13) ;Subtracts 2 Console(s) - Only Counting RDP Sessions
Next

MsgBox(0,"Restult",$result)

I read that TerminalService is a Subclass of Win32_Service. However, I can not get Win32_Service to pull anything from TermService...

So - now I have 2 options.

1) Get the DLL call to work (Which is my preferred method)

2) Get the WMI Query working with Win32_Service.

Thanks!

Edited by ZipleR

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0