473,466 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

WTSEnumerateProcesses

Hi guys,

I'm trying to get a list of processes for the current Terminal Server
session in VB.NET. It's all fine apart from I can't get the
ProcessName out of the structure WTS_PROCESS_INFO. I basically get the
first character in the WTS_PROCESSINFO.ProcessName. I know it's
something to do with the fact that it's a pointer to a string, but I
can't work out what to do about it!

The relevant code is as follows:

================================================== =============

Private Declare Auto Function WTSEnumerateProcesses Lib
"wtsapi32.dll" ( _
ByVal hServer As Int32, ByVal Reserved As Int32, _
ByVal Version As Int32, ByRef ppProcessInfo As IntPtr, _
ByRef pCount As Int32) As Int32

Private Declare Auto Sub WTSFreeMemory Lib "wtsapi32.dll" (ByVal
pMemory As IntPtr)

Private Structure WTS_PROCESS_INFO
Dim SessionID As Integer
Dim ProcessID As Integer
Dim ProcessName As String
Dim UserSid As Integer
End Structure
Dim ptrProcessInfo As IntPtr
Dim lngPtrPos As Long
Dim intReturn As Integer
Dim intCount As Integer
Dim intProcessCount As Integer
Dim strucProcessInfo As WTS_PROCESS_INFO
intReturn =
WTSEnumerateProcesses(WTS_CURRENT_SERVER_HANDLE, 0, 1, ptrProcessInfo,
intProcessCount)

'Get the length in bytes of each structure...
lngPtrPos = ptrProcessInfo.ToInt32()

For intCount = 0 To intProcessCount - 1
strucProcessInfo = Marshal.PtrToStructure(New
IntPtr(lngPtrPos), strucProcessInfo.GetType)

Console.WriteLine("Process Name: " &
strucProcessInfo.ProcessName.ToString)
Console.WriteLine("Process ID: " &
strucProcessInfo.ProcessID.ToString)
Console.WriteLine("Session ID: " &
strucProcessInfo.SessionID.ToString)

lngPtrPos = lngPtrPos + Len(strucProcessInfo)
Next

Call WTSFreeMemory(ptrProcessInfo)

================================================== =============

Any suggestion son this one...?!

Jun 1 '06 #1
1 3049
> Private Declare Auto Function WTSEnumerateProcesses Lib
"wtsapi32.dll" ( _
ByVal hServer As Int32, ByVal Reserved As Int32, _
ByVal Version As Int32, ByRef ppProcessInfo As IntPtr, _
ByRef pCount As Int32) As Int32
Since you use Auto on the function ...

Private Structure WTS_PROCESS_INFO
Dim SessionID As Integer
Dim ProcessID As Integer
Dim ProcessName As String
Dim UserSid As Integer
End Structure


.... you should use it on the structure as well. Add the
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)>
attribute.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jun 1 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Bjorn Abelli | last post by:
Hi all, When I run a normal application I can get who started a process with the following example: Process myProcesses = Process.GetProcesses(); foreach(Process p in myProcesses) {...
1
by: Noah Coad [MVP .NET/C#] | last post by:
Howdy! I need to know what user is using which process on the system. "System.Diagnostics.Process.GetProcesseses" will return an array of processes, but I need to know if the process returned is...
2
by: Kevin Hodgson | last post by:
Is there any way in a .NET App to detect if it is being run under Terminal Server? I have some functions of my program (like launching emails, and saving files) that need to be handled...
1
by: JezB | last post by:
I want to iterate the process list looking at the processes running for the current user. So I'm using: foreach (Process p in Process.GetProcesses()) { } But I can't see any method or...
0
by: Manu | last post by:
Hi, To get the USERNAME of all process running in local/remote system I am using the WTSOpenServer and WTSEnumerateProcesses API's but when I invoke the WTSOpenServer in Windows 200...
1
by: SilviaLl | last post by:
Hola buenos dias, Estoy haciendo un programa en VB 6 que se ejecutara en remoto con Terminal Server o con CITRIX. Pero tengo que hacer un control de licencias, pensava en hacer un control por el...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.