Jump to content

Is this reg string unique to each install?


Recommended Posts


Fine this way

@echo off&setlocal enableextensions enabledelayedexpansion
for /f "tokens=*" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" /s^|findstr "S-1-5-"') do (
for /f "tokens=1,3 delims= " %%b in ('reg query "%%~a" /v "ProfileImagePath"') do (
 if errorlevel 0 (
  set userkey1="%%~c"&set userkey2="%%SystemDrive%%\%userprofile:*\=%"
  if !userkey1! equ !userkey2! set UserSID=%%a&goto next
 )
)
)
:next
if not defined UserSID echo/ SID not found&&endlocal&goto :eof
set UserKey=HKU\%UserSID:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\=%
echo/ Your Users Registry Key %UserKey%&&echo/ is set as %%UserKey%%
pause&endlocal&goto :eof

Link to comment
Share on other sites

I may be wrong here but in this line...

if errorlevel 0 if "%%~c" equ "%UserProfile%" set UserSID=%%a

The two STRINGS are not equal (for me)

"%%~c" expands to "%SystemDrive%\Documents and Settings\Nakira"

"%UserProfile%" expands to "C:\Documents and Settings\Nakira"

What about just changing the command
  • if errorlevel 0 if "%%~c" equ "%UserProfile%" set UserSID=%%a

to

  • if errorlevel 0 if "%%~fc" equ "%UserProfile%" set UserSID=%%a

Edited by Yzöwl
Link to comment
Share on other sites

Last quickfix, before looking at a rewrite!

@echo off&setlocal enableextensions
for /f "tokens=*" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" /s^|findstr "S-1-5-"') do (
for /f "tokens=1,3 delims= " %%b in ('reg query "%%~a" /v "ProfileImagePath"') do (
if errorlevel 0 (
echo/%%~c|find "%userprofile%">nul
if errorlevel 0 set UserSID=%%a
)
)
)
if not defined UserSID echo/ SID not found&&endlocal&goto :eof
set UserKey=HKU\%UserSID:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\=%
echo/ Your Users Registry Key %UserKey%&&echo/ is set as %%UserKey%%
pause&endlocal&goto :eof

Link to comment
Share on other sites

At last… :)

So all you need to do is replace the line

  • echo/ Your Users Registry Key %UserKey%&&echo/ is set as %%UserKey%%

with your registry related code, using the %UserKey% variable instead of HKCU, (HKEY_CURRENT_USER).

Example

REG ADD %UserKey%\SOFTWARE\Synaptics\SynTP\TouchPadHEXBTNPS2 /v Gestures /t REG_DWORD /d 2 /f

Note - Please make sure after pasting the code into your text editor that delims=<tab>" not delims=<space(s)>"

<Edit>

Special thanks to nakira for highlighting the cause of the problem.

</Edit>

Edited by Yzöwl
Link to comment
Share on other sites

You got it dude :hello:

C:\Documents and Settings\MYUSERNAME\Desktop>test.cmd
Your Users Registry Key HKU\S-1-5-21-1085031214-1682526488-1343024091-1003
is set as %UserKey%
Click any key to continue...

Edited by BoardBabe
Link to comment
Share on other sites

  • 1 year later...
You got it dude :hello:

C:\Documents and Settings\MYUSERNAME\Desktop>test.cmd
Your Users Registry Key HKU\S-1-5-21-1085031214-1682526488-1343024091-1003
is set as %UserKey%
Click any key to continue...

I would like to make a point that this code will NOT work in the following senario:

User 1 logs on and runs script, getting s-1-blah-1003

User 1 chooses "switch user"

User 2 logs on and runs script.

Now, the code will still display the SID from the first user that logged on, user 1. s-1-blah-1003

How do we get this code to work in this situation?

Edited by drumminforev
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
  • Recently Browsing   0 members

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