|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
WTSEnumerateProcessesI'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...?! > Private Declare Auto Function WTSEnumerateProcesses Lib Since you use Auto on the function ...>"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 Structure WTS_PROCESS_INFO .... you should use it on the structure as well. Add the> Dim SessionID As Integer > Dim ProcessID As Integer > Dim ProcessName As String > Dim UserSid As Integer > End Structure <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.
what's available in WMI
File sitting on a network drive is still open by another applicati Deleted row in dataset?? Socket and ThreadPool popup windows killer Why choose SQL Express over Access? "select case" statement optimization in VB and C# problems Soap Formatter namespace not found loading frames asp Synchronize VS2005 Projects directory? |
|||||||||||||||||||||||