Click to See Complete Forum and Search --> : HELP!!!!


January 7th, 2000, 10:46 AM
Can someone please tell me how I can convert the users SID to a string so that I can display it.

I can retrieve the USers SID by the following code
But now I need to disply it in a text box when run.
Currently all I am returning is 1
I found an "BinaryToOctetString" API but can not get it to work
HELP!!!!! (please) :-)

Thanks
tcompe

Public Const SidTypeUser = 1

Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Declare Function LookupAccountName Lib "advapi32.dll" Alias _
"LookupAccountNameA" (lpSystemName As String, _
ByVal lpAccountName As String, SID As Any, cbSid As Long, _
ByVal ReferencedDomainName As String, _
cbReferencedDomainName As Long, peUse As Long) As Long
Sub Main()
Dim lResult As Long ' Result of various API calls.
Dim bUserSid(255) As Byte ' This will contain your SID.
Dim lSystemNameLength As Long ' Length of string that contains
' the name of this system.
Dim lLengthUserName As Long ' Max length of user name.
Dim sUserName As String * 255 ' String to hold the current user
' name.
Dim lUserSID As Long ' Used to hold the SID of the
' current user.
Dim lUserSIDSize As Long ' Size of the SID.
Dim sDomainName As String * 255 ' Domain the user belongs to.
Dim lDomainNameLength As Long ' Length of domain name needed.
Dim lSIDType As Long ' The type of SID info we are
' getting back.
Dim SID As String
lLengthUserName = 255
sUserName = Space(lLengthUserName)

' Call GetUserName to find out who is logged onto this system.
lResult = GetUserName(sUserName, lLengthUserName)

' Return value of zero means the call failed; test for this before
' continuing.
If (lResult = 0) Then
MsgBox "Error: Unable to Retrieve the Current User Name"
Exit Sub
End If

lResult = LookupAccountName(vbNullString, sUserName, _
bUserSid(0), 255, sDomainName, lDomainNameLength, _
lSIDType)

' Now set the sDomainName string buffer to its proper size before
' calling the API again.
sDomainName = Space(lDomainNameLength)

' Call the LookupAccountName again to get the actual SID for user.
lResult = LookupAccountName(vbNullString, sUserName, _
bUserSid(0), 255, sDomainName, lDomainNameLength, _
lSIDType)

'Return the actual SID
SID = bUserSid(0)

' Return value of zero means the call to LookupAccountName failed;
' test for this before you continue.
If (lResult = 0) Then
MsgBox "Error: Unable to Lookup the Current User Account: " _
& sUserName
Exit Sub
Else
MsgBox "Successfully captured the Currently Logged on Users SID: " _
& SID

End If
End Sub