August 8, 200521 yr NM However, that script produces "SID not found" fo rme too, and that's the only reason I can thik of... Edited August 8, 200521 yr by nakira
August 8, 200521 yr @ nakiraI think you may be correct, if we have some more confirmations on this, I'll adjust the code to suit… Edited August 8, 200521 yr by Yzöwl
August 8, 200521 yr Fine this way@echo off&setlocal enableextensions enabledelayedexpansionfor /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 ) )):nextif not defined UserSID echo/ SID not found&&endlocal&goto :eofset 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
August 8, 200521 yr I may be wrong here but in this line...if errorlevel 0 if "%%~c" equ "%UserProfile%" set UserSID=%%aThe two STRINGS are not equal (for me)"%%~c" expands to "%SystemDrive%\Documents and Settings\Nakira""%UserProfile%" expands to "C:\Documents and Settings\Nakira"<{POST_SNAPBACK}>What about just changing the commandif errorlevel 0 if "%%~c" equ "%UserProfile%" set UserSID=%%atoif errorlevel 0 if "%%~fc" equ "%UserProfile%" set UserSID=%%a Edited August 9, 200521 yr by Yzöwl
August 8, 200521 yr 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:\)
August 8, 200521 yr Last quickfix, before looking at a rewrite!@echo off&setlocal enableextensionsfor /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 :eofset 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
August 9, 200521 yr Yzöwl that last one worked for me perfectlyBut I only have 1 user on this PC Edited August 9, 200521 yr by maxXPsoft
August 9, 200521 yr At last… So all you need to do is replace the lineecho/ 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).ExampleREG ADD %UserKey%\SOFTWARE\Synaptics\SynTP\TouchPadHEXBTNPS2 /v Gestures /t REG_DWORD /d 2 /fNote - 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 August 9, 200521 yr by Yzöwl
August 9, 200521 yr Author You got it dude 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 August 9, 200521 yr by BoardBabe
September 26, 200619 yr You got it dude 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-1003User 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-1003How do we get this code to work in this situation? Edited September 26, 200619 yr by drumminforev
September 27, 200619 yr @echo off&setlocal enableextensionsfor /f "skip=1" %%a in ('wmic useraccount where name^="%username%" get SID') do set UserKey=HKU\%%aecho * %%UserKey%% Value: %Userkey%endlocal&pause
September 27, 200619 yr @echo off&setlocal enableextensionsfor /f "skip=1" %%a in ('wmic useraccount where name^="%username%" get SID') do set UserKey=HKU\%%aecho * %%UserKey%% Value: %Userkey%endlocal&pauseMy never ending thanks go to you!Amazing!
Create an account or sign in to comment