Hi,
I posted this a while ago! To no avail!
What if I offered to pay a nominal amount via PayPal?
We'll work the finer details out later!
Cheers,
Carl.
(E-Mail Removed) (CarlEOgden) wrote in message news:<(E-Mail Removed)>...
> Hi,
>
> I've found this example but when I try to rework it for VB.Net I fail
> with the API calls and the CopyMemory procedure and to be truthful,
> it's far over my skill level with the getting information from buffers
> etc, all I've ever done with these is hack code around to get them
> working!!!
>
> Many thanks with any and all help given.
>
> Cheers,
> Carl.
>
> Code Start =============================================================
> Hi,
>
> I've found this from this group but it's in VB, can anyone convert it
> to VB.Net for me? I've tried and failed! Mainly on the copymemory. But
> I'm not too hot in .Net to begin with!!!
>
> Many thanks,
> Carl.
>
> From: Alick [MS] ((E-Mail Removed))
> Subject: RE: WTSQuerySessionInformation
> View: Complete Thread (3 articles)
> Original Format
> Newsgroups: microsoft.public.vb.winapi
> Date: 2002-11-24 22:19:25 PST
>
>
> Here is a sample using the WTSQuerySessionInformation function to
> return
> information about the specified session on the specified Terminal
> Server.
>
> Option Explicit
> Private Declare Function LoadLibrary Lib "KERNEL32" Alias
> "LoadLibraryA"
> (ByVal
> lpLibFileName As String) As Long
> Private Declare Function FreeLibrary& Lib "KERNEL32" (ByVal hLibModule
> As
> Long)
>
> Private Declare Function WTSQuerySessionInformation Lib "wtsapi32"
> Alias
> "WTSQuerySessionInformationA" _
> (ByVal hServer As Long, ByVal SessionID As Long, ByVal WTSInfoClass
> As
> Long,
> _
> ByRef ppBuffer As Long, ByRef lLen As Long) As Long
>
> Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (
> _
> hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
>
> Private Enum WTS_CONNECTSTATE_CLASS
> WTSActive
> WTSConnected
> WTSConnectQuery
> WTSShadow
> WTSDisconnected
> WTSIdle
> WTSListen
> WTSReset
> WTSDown
> WTSInit
> End Enum
>
> Private Type WTS_CLIENT_ADDRESS
> AddressFamily As Long
> Address(20) As Byte
> End Type
>
> Private Type WTS_CLIENT_DISPLAY
> HorizontalResolution As Long
> VerticalResolution As Long
> ColorDepth As Long
> End Type
>
> Private Enum WTS_INFO_CLASS
> WTSInitialProgram
> WTSApplicationName
> WTSWorkingDirectory
> WTSOEMId
> WTSSessionId
> WTSUserName
> WTSWinStationName
> WTSDomainName
> WTSConnectState
> WTSClientBuildNumber
> WTSClientName
> WTSClientDirectory
> WTSClientProductId
> WTSClientHardwareId
> WTSClientAddress
> WTSClientDisplay
> End Enum
>
> Private Const WTS_CURRENT_SERVER_HANDLE As Long = 0
> Private Const WTS_CURRENT_SESSION As Long = -1
>
> Private varWTS_CONNECTSTATE_CLASS As WTS_CONNECTSTATE_CLASS
>
> Private Sub Form_Load()
> Dim lRet As Long
> Dim lLib As Long
> Dim sVal As String
> Dim sOut As String
> Dim i As Long
>
> On Error GoTo ErrHandler
>
> lLib = LoadLibrary("Wtsapi32.dll")
> With lblNotFound
> If lLib < 1 Then
> .Caption = "DLL Not Found"
> .ForeColor = &HFF&
> Exit Sub
> Else
> .Caption = "DLL Found"
> .ForeColor = &H8000&
> End If
> End With
>
> MsgBox "About to call API"
> For i = 0 To 15
> msGetTSEValue (i)
> Next i
> Exit Sub
>
> lRet = FreeLibrary(lLib)
> Exit Sub
>
> ErrHandler:
> MsgBox Error(Err)
> End Sub
>
> Private Sub msGetTSEValue(eWTSType As WTS_INFO_CLASS)
> Dim sVal As String
> Dim lVal As Long
> Dim intVal As Integer
> Dim lRet As Long
> Dim lLen As Long
> Dim lErr As Long
> Dim lBufferAddress As Long
> Dim varWTS_CLIENT_ADDRESS As WTS_CLIENT_ADDRESS
> Dim varWTS_CLIENT_DISPLAY As WTS_CLIENT_DISPLAY
>
> lRet = WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, _
> WTS_CURRENT_SESSION, _
> eWTSType, _
> lBufferAddress, _
> lLen)
>
> ' copying the buffer to a VB string
> Select Case eWTSType
> Case 0
> MsgBox "WTSInitialProgram"
> Case 1
> MsgBox "WTSApplicationName"
> Case 2
> MsgBox "WTSWorkingDirectory"
> Case 3
> MsgBox "WTSOEMId"
> Case 4
> MsgBox "WTSSessionId"
> Case 5
> MsgBox "WTSUserName"
> Case 6
> MsgBox "WTSWinStationName"
> Case 7
> MsgBox "WTSDomainName"
> Case 8
> MsgBox "WTSConnectState"
> Case 9
> MsgBox "WTSClientBuildNumber"
> Case 10
> MsgBox "WTSClientName"
> Case 11
> MsgBox "WTSClientDirectory"
> Case 12
> MsgBox "WTSClientProductId"
> Case 13
> MsgBox "WTSClientHardwareId"
> Case 14
> MsgBox "WTSClientAddress"
> Case 15
> MsgBox "WTSClientDisplay"
> End Select
>
> If lLen > 0 Then
> Select Case eWTSType
> Case 4
> lVal = 0
> CopyMemory lVal, ByVal lBufferAddress, lLen
> MsgBox "WTSSessionId " & lVal
> Case 8
> lVal = 0
> CopyMemory lVal, ByVal lBufferAddress, lLen
> MsgBox "WTSConnectState " & lVal
> Case 9
> intVal = 0
> CopyMemory intVal, ByVal lBufferAddress, lLen
> MsgBox "WTSClientBuildNumber " & intVal
> Case 12
> intVal = 0
> CopyMemory intVal, ByVal lBufferAddress, lLen
> MsgBox "WTSClientProductId " & intVal
> Case 13
> intVal = 0
> CopyMemory intVal, ByVal lBufferAddress, lLen
> MsgBox "WTSClientHardwareId " & intVal
> Case 14
> CopyMemory varWTS_CLIENT_ADDRESS, ByVal lBufferAddress,
> lLen
> MsgBox "varWTS_CLIENT_ADDRESS " &
> varWTS_CLIENT_ADDRESS.AddressFamily
> Case 15
> CopyMemory varWTS_CLIENT_DISPLAY, ByVal lBufferAddress,
> lLen
> MsgBox "varWTS_CLIENT_DISPLAY.ColorDepth " &
> varWTS_CLIENT_DISPLAY.ColorDepth
> MsgBox "varWTS_CLIENT_DISPLAY.HorizontalResolution " &
> varWTS_CLIENT_DISPLAY.HorizontalResolution
> MsgBox "varWTS_CLIENT_DISPLAY.VerticalResolution " &
> varWTS_CLIENT_DISPLAY.VerticalResolution
> Case Else
> sVal = Space(lLen) ' allocating memory to the VB string to
> be
> able
> to store the buffer
> CopyMemory ByVal sVal, ByVal lBufferAddress, lLen
> MsgBox "sval " & sVal
> End Select
> End If
>
> If lRet = 0 Then
> lErr = Err.LastDllError
> MsgBox "Error code reported from LastDllError: " & lErr
> End If
>
> End Function
>
> Hope it helps.
>
>
>
>
> Sincerely,
>
> Alick Ye, MCSD
> Product Support Services
> Microsoft Corporation