Link to home
Start Free TrialLog in
Avatar of j2k
j2k

asked on

How to get the textual SID/SDDL of the currently logged in user of Windows 2000/XP in VB6?

Hi,

How can I get the SID/SDDL of the currently logged in user of Windows 2000 or XP in Visual Basic 6?

It should return the value in the form of the following (as an example):

S-1-5-21-1275210071-562591055-839522115-1010

The result should be the same as the SID/SDDL within the C:\RECYCLER folder for the logged in user.

This is worth 500 points as it is quite urgent.

Thanks.
Avatar of Shane Russell
Shane Russell
Flag of United Kingdom of Great Britain and Northern Ireland image

That can easily be ported to vb 6 as that is just vbscript :)

If you need a hand converting it post back :)
ASKER CERTIFIED SOLUTION
Avatar of Shane Russell
Shane Russell
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of j2k
j2k

ASKER

Excellent! That worked perfectly. Grade A!

Thanks a million
your welcome :) Thanks for the points and grade and glad I could help you out :)

Did you leave it as is with regards to going through all the accounts or did you put an if statement in there to catch the specific user ?
Avatar of j2k

ASKER

Hi there,

I used an If statement in conjunction with the GetUserName API to catch the currently logged in user.

Thanks once again. You deserved the Grade A. :)
Avatar of j2k

ASKER

For reference, here is the full code I used:

Public Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal UserName As String, ByRef BuffSize As Long) As Long

Public Function GetMySID()
Dim objWMIService, colItems
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Account", , 48)
For Each objitem In colItems
    If objitem.Name = CurrentUser Then
        GetMySID = objitem.sid
        Exit For
    End If
Next
End Function

Public Function CurrentUser() As String
Dim sBuff As String * 512
Dim X As Long
CurrentUser = ""
X = GetUserName(sBuff, Len(sBuff) - 1)
If X > 0 Then
X = InStr(sBuff, vbNullChar)
If X > 0 Then CurrentUser = Left$(sBuff, X - 1)
End If
End Function