VB Beispiel in VBScript übernehmen



Hallo zusammen

ich habe ein Visual Basic Sample das einige externe Prozeduren verwendet.
Ich möchte dieses nun als VBScript laufen lassen, weiss aber nicht wie ich
das Ding zum laufen kriege (Typenfehler etc.)

Kann mir jemand helfen?

Dies ist das Visual Basic Sample:

Option Explicit

Private Const WTS_CURRENT_SERVER_HANDLE = 0&

Private Enum WTS_CONNECTSTATE_CLASS
WTSActive
WTSConnected
WTSConnectQuery
WTSShadow
WTSDisconnected
WTSIdle
WTSListen
WTSReset
WTSDown
WTSInit
End Enum

Private Type WTS_SESSION_INFO
SessionID As Long
pWinStationName As Long
state As WTS_CONNECTSTATE_CLASS
End Type

Private Declare Function WTSEnumerateSessions _
Lib "wtsapi32.dll" Alias "WTSEnumerateSessionsA" ( _
ByVal hServer As Long, ByVal Reserved As Long, _
ByVal Version As Long, ByRef ppSessionInfo As Long, _
ByRef pCount As Long _
) As Long

Private Declare Sub WTSFreeMemory Lib "wtsapi32.dll" ( _
ByVal pMemory As Long)

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
Destination As Any, Source As Any, ByVal length As Long)

Private Declare Function lstrlenA Lib "kernel32" ( _
ByVal lpString As String) As Long

Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" ( _
ByVal lpString1 As String, ByVal lpString2 As Long) As Long

Private arrWTSSessions() As WTS_SESSION_INFO

Private Function GetWTSSessions() As WTS_SESSION_INFO()
Dim RetVal As Long
Dim lpBuffer As Long
Dim Count As Long
Dim p As Long
Dim arrSessionInfo() As WTS_SESSION_INFO

RetVal = WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, _
0&, _
1, _
lpBuffer, _
Count)
If RetVal Then
' WTSEnumerateProcesses was successful.

p = lpBuffer
ReDim arrSessionInfo(Count - 1)
CopyMemory arrSessionInfo(0), ByVal p, _
Count * LenB(arrSessionInfo(0))
' Free the memory buffer.
WTSFreeMemory lpBuffer

Else
' Error occurred calling WTSEnumerateProcesses.
' Check Err.LastDllError for error code.
MsgBox "An error occurred calling WTSEnumerateProcesses. " & _
"Check the Platform SDK error codes in the MSDN Documentation " & _
"for more information.", vbCritical, "ERROR " & Err.LastDllError
End If
GetWTSSessions = arrSessionInfo
End Function

Private Sub Command1_Click()
Dim i As Integer

arrWTSSessions = GetWTSSessions
For i = LBound(arrWTSSessions) To UBound(arrWTSSessions)
Debug.Print "Session ID: " & arrWTSSessions(i).SessionID
Debug.Print "Machine Name: " & _
PointerToStringA(arrWTSSessions(i).pWinStationName)
Debug.Print "Connect State: " & arrWTSSessions(i).state
Debug.Print "***********"
Next i
End Sub

Public Function PointerToStringA(ByVal lpStringA As Long) As String
Dim nLen As Long
Dim sTemp As String

If lpStringA Then
nLen = lstrlenA(ByVal lpStringA)
If nLen Then
sTemp = String(nLen, vbNullChar)
lstrcpy sTemp, ByVal lpStringA
PointerToStringA = sTemp
End If
End If
End Function

Besten Dank für eure Antworten
Viele Grüsse
Patrick
.