Get Current Desktop Name
Visual Basic
2
Posts
2
Posters
0
Views
1
Watching
-
Hi, I need to know the name od the current windows desktop in vb6. I use the following code.
l
which is the lenght of the string of desktop name, is filled but, the strigs
would not be filled. I would like to ask why this happens, and if there are any other methods to get current desktop name?Option Explicit Private Declare Function GetUserObjectInformation Lib "user32" Alias "GetUserObjectInformationA" (ByVal hObj As Long, ByVal nIndex As Long, pvInfo As Any, ByVal nLength As Long, lpnLengthNeeded As Long) As Long Private Declare Function GetThreadDesktop Lib "user32" (ByVal dwThread As Long) As Long Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long Private Const UOI_NAME As Long = 2 Private Function GetCurrentDesktopName() As String Dim s As String, l As Long Const MAX As Long = 500 s = String(65355, vbNullChar) If GetUserObjectInformation(GetThreadDesktop(GetCurrentThreadId), UOI_NAME, VarPtr(s), MAX) Then GetCurrentDesktopName = Left(s, l - 1) End If End Function Private Sub Command1_Click() MsgBox GetCurrentDesktopName End Sub
-
Hi, I need to know the name od the current windows desktop in vb6. I use the following code.
l
which is the lenght of the string of desktop name, is filled but, the strigs
would not be filled. I would like to ask why this happens, and if there are any other methods to get current desktop name?Option Explicit Private Declare Function GetUserObjectInformation Lib "user32" Alias "GetUserObjectInformationA" (ByVal hObj As Long, ByVal nIndex As Long, pvInfo As Any, ByVal nLength As Long, lpnLengthNeeded As Long) As Long Private Declare Function GetThreadDesktop Lib "user32" (ByVal dwThread As Long) As Long Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long Private Const UOI_NAME As Long = 2 Private Function GetCurrentDesktopName() As String Dim s As String, l As Long Const MAX As Long = 500 s = String(65355, vbNullChar) If GetUserObjectInformation(GetThreadDesktop(GetCurrentThreadId), UOI_NAME, VarPtr(s), MAX) Then GetCurrentDesktopName = Left(s, l - 1) End If End Function Private Sub Command1_Click() MsgBox GetCurrentDesktopName End Sub