A
andrewbb
I'm trying to find the SID of the user who owns the desktop, but the
SID that's returned isn't recognizable. Is it a problem with the
declaration/marshaling?
The SID that's returned is: 130000055000000010620300 which isn't
like anything on this machine. The SecurityIdentifer class doesn't
recognize it as a SID either.
<DllImport("user32.dll", SetLastError:=True)> _
Private Shared Function OpenDesktop(ByVal lpszDesktop As String, ByVal
dwFlags As Integer, ByVal fInderit As Boolean, ByVal dwDesiredAccess
As Integer) As IntPtr
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Private Shared Function GetUserObjectInformation(ByVal hObj As IntPtr,
ByVal nIndex As Integer, <MarshalAs(UnmanagedType.LPArray)> ByVal
pvInfo As Byte(), ByVal nLength As Integer, ByRef lpnLengthNeeded As
Integer) As Boolean
End Function
Dim length As Integer
Dim success As Boolean
Dim buf(99) As Byte
Dim desk As IntPtr = OpenInputDesktop(0, True, DESKTOP_READOBJECTS)
success = GetUserObjectInformation(desk, UOI_USER_SID, buf, 100,
length)
Dim ret As New StringBuilder(length)
For i As Integer = 0 To length - 1
ret.Append(CStr(buf(i)))
Next
return ret.ToString() 'returns 130000055000000010620300
SID that's returned isn't recognizable. Is it a problem with the
declaration/marshaling?
The SID that's returned is: 130000055000000010620300 which isn't
like anything on this machine. The SecurityIdentifer class doesn't
recognize it as a SID either.
<DllImport("user32.dll", SetLastError:=True)> _
Private Shared Function OpenDesktop(ByVal lpszDesktop As String, ByVal
dwFlags As Integer, ByVal fInderit As Boolean, ByVal dwDesiredAccess
As Integer) As IntPtr
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Private Shared Function GetUserObjectInformation(ByVal hObj As IntPtr,
ByVal nIndex As Integer, <MarshalAs(UnmanagedType.LPArray)> ByVal
pvInfo As Byte(), ByVal nLength As Integer, ByRef lpnLengthNeeded As
Integer) As Boolean
End Function
Dim length As Integer
Dim success As Boolean
Dim buf(99) As Byte
Dim desk As IntPtr = OpenInputDesktop(0, True, DESKTOP_READOBJECTS)
success = GetUserObjectInformation(desk, UOI_USER_SID, buf, 100,
length)
Dim ret As New StringBuilder(length)
For i As Integer = 0 To length - 1
ret.Append(CStr(buf(i)))
Next
return ret.ToString() 'returns 130000055000000010620300