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-562591 055-839522 115-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.
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-562591
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.
That can easily be ported to vb 6 as that is just vbscript :)
If you need a hand converting it post back :)
If you need a hand converting it post back :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent! That worked perfectly. Grade A!
Thanks a million
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 ?
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 ?
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. :)
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. :)
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:\\.\ro ot\cimv2")
Set colItems = objWMIService.ExecQuery("S elect * 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
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:\\.\ro
Set colItems = objWMIService.ExecQuery("S
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
http://www.windowsitpro.com/WindowsScripting/Article/ArticleID/25287/25287.html