Jump to content

Retrieve user GUID from reg to set as VAR?


Recommended Posts

Would I be able to retrieve a logged in users GUID ID from the reg and set it as a var? for example my current GUID ID is S-1-5-21-3783412348-3147957303-627458716-1003 I was thinking of setting that as a var. I have a Key and a value that I need to be dynamic but gets stored in the HKU\S-1-5-21-3783412348-3147957303-627458716-1003 Key.

The closest I could come up with is below but im not sure if this will work on any XP/2003 system. This is just a test to see if it will retrieve the correct code. All I really need is to be able to set that KEY as the $var. Even so I kinda need to full path to be the var. not just the GUID.

For $i= 1 to 10
    $var = RegEnumKey("HKEY_CURRENT_USER\Software\Microsoft\Protected Storage System Provider", $i)
    If @error <> 0 then ExitLoop
    MsgBox(4096, "SubKey #" & $i & " under HKU\Software\Microsoft\Protected Storage System Provider: ", $var)
Next

Thanks,

MrChris

Edited by MrChris
Link to comment
Share on other sites

Would I be able to retrieve a logged in users GUID ID from the reg and set it as a var? for example my current GUID ID is S-1-5-21-3783412348-3147957303-627458716-1003 I was thinking of setting that as a var. I have a Key and a value that I need to be dynamic but gets stored in the HKU\S-1-5-21-3783412348-3147957303-627458716-1003 Key.

The closest I could come up with is below but im not sure if this will work on any XP/2003 system. This is just a test to see if it will retrieve the correct code. All I really need is to be able to set that KEY as the $var. Even so I kinda need to full path to be the var. not just the GUID.

For $i= 1 to 10
    $var = RegEnumKey("HKEY_CURRENT_USER\Software\Microsoft\Protected Storage System Provider", $i)
    If @error <> 0 then ExitLoop
    MsgBox(4096, "SubKey #" & $i & " under HKU\Software\Microsoft\Protected Storage System Provider: ", $var)
Next

Thanks,

MrChris

This might be usefull for me too, so I did some preliminay Googling. I came up with the following statement: "The GetUserNameEx() call can be made to retrieve the current user's GUID or other unique information,..."

But I haven't tracked down using that GetUserNameEx() Windows API yet. Will have more resources available later.

:whistle:

Edit: Looks like the "NameUniqueId -- A GUID string that the IIDFromString function returns (for example, {4fa050f0-f561-11cf-bdd9-00aa003a77b6})." would be the NameFormat desired from the GetUserNameEx() function.

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Well, if you are not adverse to using WMI, I ripped this off from a VBScript (http://www.codecomments.com/archive299-2005-6-515041.html). Requires beta.

$oWMI = ObjGet("winmgmts://./root/cimv2")
$oUser = $oWMI.Get("Win32_UserAccount.Domain='" & @LogonDomain & "'" _
    & ",Name='" & @UserName & "'")
$sUserSID = $oUser.SID
MsgBox(0, "UserSID", $sUserSID)
BlueBearrOddly enough, this is what I do for fun.
Link to comment
Share on other sites

OK This is what I have come up with so far but am having trouble getting the syntax correct. The problem I think is with the $guid var in the RegWrite function. Maybe?

The below key in RegEnumKey is the only place in the Reg that I could find the current logged in users GUID from.

#NoTrayIcon

$i = 1
$guid = RegEnumKey("HKEY_CURRENT_USER\Software\Microsoft\Protected Storage System Provider", $i)
;MsgBox(4096, "User GUID" & $i & " Your User GUID is: ", $guid)


; Sample
RegWrite('HKEY_USERS' $guid & '\Software\KEY\SUBKEY','DATA','REG_DWORD','VALUE')
RegWrite('HKEY_USERS' $guid & '\Software\KEY\SUBKEY','DATA','REG_DWORD','VALUE1')
RegWrite('HKEY_USERS' $guid & '\Software\KEY\SUBKEY','username','REG_SZ',@UserName)

Thanks in advance,

MrChris

Link to comment
Share on other sites

Well, if you are not adverse to using WMI, I ripped this off from a VBScript (http://www.codecomments.com/archive299-2005-6-515041.html). Requires beta.

$oWMI = ObjGet("winmgmts://./root/cimv2")
$oUser = $oWMI.Get("Win32_UserAccount.Domain='" & @LogonDomain & "'" _
    & ",Name='" & @UserName & "'")
$sUserSID = $oUser.SID
MsgBox(0, "UserSID", $sUserSID)
Sweet thanks, I will give it a shot.

MrChris

Link to comment
Share on other sites

Try changing this:

RegWrite('HKEY_USERS' $guid & '\Software\KEY\SUBKEY','DATA','REG_DWORD','VALUE')oÝ÷ ÚÚ-+ºÚ"µÍYÕÜ]J    ÌÎNÒÑVWÕTÑTÉÌLÉÌÎNÈ [È ÌÍÙÝZY  [È ÌÎNÉÌLÔÛÙØIÌLÒÑVIÌLÔÕPÑVIÌÎNË ÌÎNÑUIÌÎNË    ÌÎNÔQ×ÑÓÔ    ÌÎNË ÌÎNÕSQIÌÎNÊ

of course, VALUE should be a DWORD.

Edited by bluebearr
BlueBearrOddly enough, this is what I do for fun.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...