maxXPsoft Posted August 8, 2005 Posted August 8, 2005 (edited) %SystemDrive% = C: Edited August 8, 2005 by maxXPsoft
nakira Posted August 8, 2005 Posted August 8, 2005 (edited) NM However, that script produces "SID not found" fo rme too, and that's the only reason I can thik of... Edited August 8, 2005 by nakira
Yzöwl Posted August 8, 2005 Posted August 8, 2005 (edited) @ nakiraI think you may be correct, if we have some more confirmations on this, I'll adjust the code to suit… Edited August 8, 2005 by Yzöwl
nakira Posted August 8, 2005 Posted August 8, 2005 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
Yzöwl Posted August 8, 2005 Posted August 8, 2005 (edited) 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, 2005 by Yzöwl
nakira Posted August 8, 2005 Posted August 8, 2005 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:\)
Yzöwl Posted August 8, 2005 Posted August 8, 2005 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
maxXPsoft Posted August 9, 2005 Posted August 9, 2005 (edited) Yzöwl that last one worked for me perfectlyBut I only have 1 user on this PC Edited August 9, 2005 by maxXPsoft
Yzöwl Posted August 9, 2005 Posted August 9, 2005 (edited) 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, 2005 by Yzöwl
BoardBabe Posted August 9, 2005 Author Posted August 9, 2005 (edited) 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, 2005 by BoardBabe
drumminforev Posted September 26, 2006 Posted September 26, 2006 (edited) 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, 2006 by drumminforev
nakira Posted September 27, 2006 Posted September 27, 2006 @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
drumminforev Posted September 27, 2006 Posted September 27, 2006 @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!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now