Results 1 to 6 of 6

Thread: Display User's SID

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2004
    Posts
    39

    Unhappy Display User's SID

    The following code displays the selected SID's number.

    In my case S-1-5-21-1123561954-2054111206-734534423-1009

    VB Code:
    1. Private Declare Function ConvertSidToStringSid Lib "ADVAPI32.dll" Alias "ConvertSidToStringSidA" (ByVal Sid As String, ByRef lpStringSid As Long) As Long
    2. Private Declare Function IsValidSid Lib "ADVAPI32.dll" (ByRef pSid As Any) As Long
    3. Private Declare Function LookupAccountName Lib "ADVAPI32.dll" Alias "LookupAccountNameA" (ByVal lpSystemName As String, ByVal lpAccountName As String, ByVal Sid As String, ByRef cbSid As Long, ByVal ReferencedDomainName As String, ByRef cbReferencedDomainName As Long, ByRef peUse As Long) As Long
    4. Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
    5. Private Declare Function GlobalFree Lib "kernel32.dll" (ByVal hMem As Long) As Long
    6. Private Declare Function LocalAlloc Lib "kernel32.dll" (ByVal wFlags As Long, ByVal wBytes As Long) As Long
    7. Private Declare Function LocalFree Lib "kernel32.dll" (ByVal hMem As Long) As Long
    8.  
    9. Private Sub Command1_Click()
    10.  
    11. UserSID = GetSid(Text1.Text & "\" & Text2.Text)
    12.  
    13. Text3.Text = UserSID
    14. End Sub
    15.  
    16.  
    17. Private Function GetSid(accountName As String) As String
    18.  
    19. Dim userName As String
    20. Dim UserNameSize As Long
    21. Dim Sid As String
    22. Dim SidSize As Long
    23. Dim Domain As String
    24. Dim DomainSize As Long
    25. Dim snu As Long
    26. Dim sReturn As String
    27.  
    28. userName = String$(255, 0&)
    29. Sid = String$(255, 0&)
    30. Domain = String$(255, 0&)
    31. sReturn = String$(255, 0&)
    32.  
    33. UserNameSize = 255
    34. SidSize = 255
    35. DomainSize = 255
    36.  
    37. Call LookupAccountName(vbNullString, accountName, Sid, SidSize, Domain, DomainSize, snu)
    38. If IsValidSid(ByVal Sid) = 0& Then Exit Function
    39.  
    40. Call ConvertSidToStringSid(Sid, snu)
    41. Call CopyMemory(ByVal sReturn, ByVal snu, 255)
    42.  
    43. sReturn = Left$(sReturn, InStr(vbNull, sReturn, vbNullChar, vbBinaryCompare) - vbNull)
    44. Call GlobalFree(snu)
    45.  
    46. GetSid = sReturn
    47. End Function

    My question is. Why doesn't the number I get match with any of my HKEY_USERS ?

    S-1-5-18
    S-1-5-19
    S-1-5-20

    Thank you

  2. #2
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Display User's SID

    Because they are LocalSystem account used by the service control manager.

    Check this link from MSDN.

    And why you should not fiddle with them.

    And the result you are getting is the SID of the current logged-in account.
    Show Appreciation. Rate Posts.

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2004
    Posts
    39

    Re: Display User's SID

    I want to login as an administrator, select a local user from a list, and make a change on the selected User's registry Key.
    I was reading someplace that to do this I have to load the profile first to make it visible under HKEY_USERS. Is that what I need to do?

  4. #4
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Display User's SID

    what is an SID? is it pronounced "S-I-D"? or "Sid"?
    My usual boring signature: Something

  5. #5
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Display User's SID

    Quote Originally Posted by dclamp
    what is an SID? is it pronounced "S-I-D"? or "Sid"?
    its a security identifier

  6. #6
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Display User's SID

    Quote Originally Posted by guayo
    I want to login as an administrator, select a local user from a list, and make a change on the selected User's registry Key.
    I was reading someplace that to do this I have to load the profile first to make it visible under HKEY_USERS. Is that what I need to do?
    Are you tryin to do it programmatically?? Well I know how to run a process / application as another user, but I doubt if you can do so much of work through it.

    To run a process as another user, look for LogonUser, CreateProcessAsUser, and CreateProcessWithLogonW ( this is not available for 9x, and Me, AFAIK) APIs.

    If you are just doing it manually, and at the same time, you are not logged in as an Administrator,
    • Goto %SYSTEMROOT% (C:\Windows in XP), right-click "Regedit.exe", and click "Run As..." in the context menu.
    • Select "Run as Another user", enter the username as Administrator and its password, click OK.
    • Make sure that you have "Show Hidden Files and Folders" chekced in Folder options.
    • Check the HK_Users Hive, you will have the 3 LocalSystem accounts, hive of current logged in account, and hive of administrator.
    • Highlight Hkey_Users, and in the File menu, click "Load Hive".
    • Goto "C:\Documents and Settings\Desired Account name\" and look for "NTUSER.DAT" file.
    • Click on this file, click OK, then enter the Alias name for the loading hive.
    • You are ready to set/unset the registry properties of another user.


    Disclaimer: The original poster, guayo, hereby agree that he/she takes entire responsibilty for any damage or error that occurs due to the above procedure to change registry settings. I, Harsh Gupta, am not responsible for any negative effect.

    Warning: If you have no experience with Registry, don't play with it. It could result in crashing of your entire system.
    Show Appreciation. Rate Posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width