So,
ich nochmal.
Also irgendwie komme ich nicht wirklich zurecht mit dem Umproggen auf .NET.
Der Source funktioniert auf jeden Fall in vb6 (habe ich getestet).
Aber irgendwie liefert mir die API kein oder ein falsches ergebnis.
Hier die Basis des Codes:
Private Const WTS_CURRENT_SERVER_HANDLE As Long = 0
Public Enum WTSInfoClass
WTSInitialProgram
WTSApplicationName
WTSWorkingDirectory
WTSOEMID
WTSSessionId
WTSUserName
WTSWinStationName
WTSDomainName
WTSConnectState
WTSClientBuilderNumber
WTSClientName
WTSClientDirectory
WTSClientProductId
WTSClientHardwareId
WTSClientAddress
WTSClientDisplay
WTSClientProtocolType
End Enum
'WTS Sitzungsanfragen-Struktur
Public Structure WTS_SESSION_QUERY
Public SessionID As Long
Public pWinStationName As Long
Public WTSClientName As String
Public senum As WTSInfoClass
End Structure
'Funktionsdefinition API-Aufruf für Session-Daten auslesen
<DllImport("wtsapi32.dll", EntryPoint:="WTSQuerySessionInformationA", _
CharSet:=CharSet.Unicode)> _
Private Function WTSQuerySessionInformation _
(ByVal hServer As Long, ByVal SessionID As Long, _
ByVal WTS_INFO_CLASS As WTSInfoClass, ByRef QSbuffer As Long, _
ByRef pCount As Long) As Int32
End Function
'Funktionsdefinition für API-Aufruf "Speicher freigeben",
<DllImport("wtsapi32.dll", CharSet:=CharSet.Unicode)> _
Private Sub WTSFreeMemory(ByVal pMemory As Long)
End Sub
'String API's
<DllImport("kernel32.dll", EntryPoint:="lstrcpyA", _
CharSet:=CharSet.Unicode)> _
Private Function StrCopyA(ByVal retval As String, ByVal Ptr As Long) As Long
End Function
<DllImport("kernel32.dll", EntryPoint:="lstrlenA", _
CharSet:=CharSet.Unicode)> _
Private Function StrLenA(ByVal Ptr As Long) As Long
End Function
'Funktion für Auslesen des RDP-Hostnames
Public Function GetWTSQueryHost(ByVal SessionID As Long) As String
Dim retval As Int32
Dim lpBuffer As Long
Dim p As Long
Dim Count As Long
Dim lName As Long
Dim sName As String
Try
'Remotesitzungsinformationen holen
retval = WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, _
SessionID, WTSInfoClass.WTSClientName, lpBuffer, Count)
End Function Die Variable lpBuffer ist und bleibt beim API call = 0 im VB6 Code bekomme ich in jedem Falle ein Wert zurück. Irgendwas mache ich falsch.
Leider muß ich gestehen, das ich auch in der Vergangenheit sehr wenig mit API´s gemacht habe, war immer froh wenn die Beispiele die ich genutzt habe funktionierten.
HILFE... ist schon ein komisches Gefühl keinen Plan zu haben an was es liegen könnte.
Wäre nett wenn jemand mal den .net code checken könnte ob da was falsch dran ist.
Danke Ecuh vielmals... |