Jump to content

Recommended Posts


Posted (edited)

NM :D

However, that script produces "SID not found" fo rme too, and that's the only reason I can thik of...

Edited by nakira
Posted (edited)

@ nakira

I think you may be correct, if we have some more confirmations on this, I'll adjust the code to suit…

Edited by Yzöwl
Posted

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

Posted (edited)
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
Posted

No go, that ends up like this

"C:\Documents and Settings\Nakira\Desktop\Settings\Nakira" (run from desktop)

or

"C:\Settings\Nakira" (run from C:\)

Posted

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

Posted (edited)

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
Posted (edited)

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
  • 1 year later...
Posted (edited)
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
Posted
@echo off&setlocal enableextensions
for /f "skip=1" %%a in ('wmic useraccount where name^="%username%" get SID') do set UserKey=HKU\%%a
echo * %%UserKey%% Value: %Userkey%
endlocal&pause

Posted
@echo off&setlocal enableextensions
for /f "skip=1" %%a in ('wmic useraccount where name^="%username%" get SID') do set UserKey=HKU\%%a
echo * %%UserKey%% Value: %Userkey%
endlocal&pause

My never ending thanks go to you!

Amazing!

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...