API in vb.net - OpenInputDesktop and GetUserObjectInformation

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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

.



Relevant Pages

  • RE: File Security Descriptor
    ... > Dim bUserSid(255) As Byte ' This will contain your SID. ... > the ACL. ... > Dim sNewSD As SECURITY_DESCRIPTOR ' New security descriptor. ...
    (microsoft.public.vb.general.discussion)
  • RE: Network authentication
    ... I have added an article below that tells you how to clear the Sid History ... Use Visual Basic Script to Clear SidHistory ... Dim strFilter 'As String ... Dim oConnection 'As ADODB.Connection ...
    (microsoft.public.win2000.security)
  • Re: Run-Time Error 2501
    ... Dim stDocName As String ... Dim SID As String ...
    (microsoft.public.access.formscoding)
  • AfterUpdate help
    ... In the LookUpItem drop down I have added the AfterUpdate ... Dim SID As String ... Dim rsc As DAO.Recordset ... Set rsc = Me.RecordsetClone ...
    (microsoft.public.access.forms)
  • Re: API in vb.net - OpenInputDesktop and GetUserObjectInformation
    ... I thought I would be receiving the SID of the account that owns the ... ByRef stringSID As IntPtr) As Integer ... Dim desk As IntPtr = OpenInputDesktop ...
    (microsoft.public.dotnet.languages.vb)