|
-
Nov 24th, 2006, 04:15 PM
#1
Thread Starter
Member
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:
Private Declare Function ConvertSidToStringSid Lib "ADVAPI32.dll" Alias "ConvertSidToStringSidA" (ByVal Sid As String, ByRef lpStringSid As Long) As Long
Private Declare Function IsValidSid Lib "ADVAPI32.dll" (ByRef pSid As Any) As Long
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
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
Private Declare Function GlobalFree Lib "kernel32.dll" (ByVal hMem As Long) As Long
Private Declare Function LocalAlloc Lib "kernel32.dll" (ByVal wFlags As Long, ByVal wBytes As Long) As Long
Private Declare Function LocalFree Lib "kernel32.dll" (ByVal hMem As Long) As Long
Private Sub Command1_Click()
UserSID = GetSid(Text1.Text & "\" & Text2.Text)
Text3.Text = UserSID
End Sub
Private Function GetSid(accountName As String) As String
Dim userName As String
Dim UserNameSize As Long
Dim Sid As String
Dim SidSize As Long
Dim Domain As String
Dim DomainSize As Long
Dim snu As Long
Dim sReturn As String
userName = String$(255, 0&)
Sid = String$(255, 0&)
Domain = String$(255, 0&)
sReturn = String$(255, 0&)
UserNameSize = 255
SidSize = 255
DomainSize = 255
Call LookupAccountName(vbNullString, accountName, Sid, SidSize, Domain, DomainSize, snu)
If IsValidSid(ByVal Sid) = 0& Then Exit Function
Call ConvertSidToStringSid(Sid, snu)
Call CopyMemory(ByVal sReturn, ByVal snu, 255)
sReturn = Left$(sReturn, InStr(vbNull, sReturn, vbNullChar, vbBinaryCompare) - vbNull)
Call GlobalFree(snu)
GetSid = sReturn
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
-
Nov 24th, 2006, 04:45 PM
#2
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.
-
Nov 24th, 2006, 05:27 PM
#3
Thread Starter
Member
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?
-
Nov 24th, 2006, 07:15 PM
#4
Re: Display User's SID
what is an SID? is it pronounced "S-I-D"? or "Sid"?
My usual boring signature: Something
-
Nov 24th, 2006, 07:59 PM
#5
PowerPoster
Re: Display User's SID
 Originally Posted by dclamp
what is an SID? is it pronounced "S-I-D"? or "Sid"?
its a security identifier
-
Nov 25th, 2006, 08:34 AM
#6
Re: Display User's SID
 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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|