Program show crash after migrated from Windows 2003 Server to Windows 2012 Server and crash happen at CopyMemory
Can anyone help to modify the code ?
Public Function GetClientName() As String
Dim strClientName As String
Dim strCharacter As String
Dim intLoop As Integer
Dim pBuffer As Long
Dim dwSize As Long
GetClientName = ""
If WTSQuerySessionInformation(0, -1, 10, pBuffer, dwSize) Then
Dim clientName As String
clientName = String(dwSize, 0)
CopyMemory ByVal StrPtr(clientName), ByVal pBuffer, dwSize
WTSFreeMemory pBuffer
strClientName = clientName
For intLoop = 1 To Len(strClientName)
strCharacter = Trim(Mid(strClientName, intLoop, 1))
If (Asc(strCharacter) >= 48 And Asc(strCharacter) <= 57) Or (Asc(strCharacter) >= 65 And Asc(strCharacter) <= 90) Or _
(Asc(strCharacter) >= 97 And Asc(strCharacter) <= 122) Then
Debug.Print Asc(strCharacter)
GetClientName = GetClientName & strCharacter
End If
Next intLoop
End If
End Function
Can anyone help to modify the code ?