midiboy Posted July 19, 2004 Posted July 19, 2004 Hi guys !Maybe someone can help me here. I have this little batch file to extract the Personal folders name from the registry and set HOMEDRIVE and HOMEPATH variables accordingly:FOR /F "TOKENS=3" %%i in ('reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Personal ^| FINDSTR "REG_SZ"') do set HOMEPATH =%%iSET HOMEDRIVE=%HOMEPATH:~0,2%SET HOMEPATH=%HOMEPATH:~-2,0%Now I have two problems:1.The first part ( the extraction off the registry ) works fine when calling the cmd in Windows. However the second part does not. I always get the following results:HOMEDRIVE=~0,2HOMEPATH=~-2,0HOMEPATH =D:\AlexanderAny ideas ?2.The second problem appears when running the cmd from the run command in HKCU\Software\Microsoft\Windows\CurrentVersion\Run with this command:cmd /c "%USERPROFILE%\home.cmd"When I then call the environment variables, HOMEPATH still points to the default USERSPROFILE and not to D:\Alexander. Maybe someone can help !Thanks,Alex
midiboy Posted July 19, 2004 Author Posted July 19, 2004 @rdalling:Is this a joke ? I wouldn´t not go through all this if I wanted to do this manually. What if username is not Alexander ? What if the Personals folder is on E:\Data\2536myfolder87 ??Bye,Alex
rdalling Posted July 19, 2004 Posted July 19, 2004 Ok heres the drillI set my user folder this way...CMDLINES.TXTREGEDIT /S HKCU.regHKCU.REGWindows Registry Editor Version 5.00;Data locations [HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders]"Personal" ="D:\\Data""My Video" ="D:\\Data\\My Video""My Music" ="D:\\Data\\My Music""My Pictures"="D:\\Data\\My Pictures"so in other words NO, it is NOT a jokeNotice the double backslash, manupulate your string to have the double backslash and try again...Rogeredit if that is not what your looking for, please post some more information on what your trying to do...
Alanoll Posted July 19, 2004 Posted July 19, 2004 this is what i used to use to get values form the registrySET KEY1="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup"SET KEY2="HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\Scsi\Scsi Port 0\Scsi Bus 0\Target Id 0\Logical Unit Id 0"SET XPCD=SourcePathSET HPID=Identifierfor /f "skip=4 tokens=2*" %%a in ('reg query %KEY1% /v "%XPCD%"') do set XPCD=%%bfor /f "skip=4 tokens=2*" %%a in ('reg query %KEY2% /v "%HPID%"') do set HPID=%%b
midiboy Posted July 19, 2004 Author Posted July 19, 2004 Hi !@AlanollThanks, but this looks similar to the part in my code that already works. The part that does not work yet is seperating driveletter (homedrive: D:) and path (homepath:\Alexander ) ...Also ... why does the cmd work from within windows but not when called from the RUN registry key ?@rdalling:No, that is not what I am looking for. I do not need a way to change shell folders, I need a way to adapt the global HOMEDRIVE and HOMEPATH variables to point to the current User Shell folder "Personal" after each reboot.So if the user changes the Personals folder, then the Homedrive/Homepath variables should change accordingly.Thanks for your help !Alex
midiboy Posted July 21, 2004 Author Posted July 21, 2004 PLEASE !!Could someone help out ? I spent 10 hours now trying to get this to work. I came up with this:FOR /F "TOKENS=3" %%i in ('reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Personal') do REG ADD HKCU\Environment /v HOME /t REG_EXPAND_SZ /d %%i /fWhat it does is, it gets the location of the Personal folder from the registry and then add this path to the Environment variables.THIS WORKS when calling the batch file in Windows.However, it does NOT work when calling it from the RUN key in HKCU\Software\Microsoft\Windows\CurrentVersion\.I tried all of this:cmd /c "%USERPROFILE%\home.cmd" orcmd /c %USERPROFILE%\home.cmd orcmd /c %USERPROFILE%\\home.cmd orcmd /c %%USERPROFILE%%\\home.cmd orcmd /c %%USERPROFILE%%\home.cmd orcmd /c "%%USERPROFILE%%\home.cmd" orwithout the cmd /c ....Nothing works. The key does not get written to the registry Alex
midiboy Posted July 21, 2004 Author Posted July 21, 2004 pah ! have found the solution myself .... FOR /F "TOKENS=3" %%i in ('reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Personal') do REG ADD "HKCU\Volatile Environment" /v HOMEDRIVE /t REG_EXPAND_SZ /d "%%~di" /f FOR /F "TOKENS=3" %%j in ('reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Personal') do REG ADD "HKCU\Volatile Environment" /v HOMEPATH /t REG_EXPAND_SZ /d "%%~pnj" /fand calling it from the registry did not work because the type was REG_SZ and not REG_EXPAND_SZ so it did not expand the %USERPROFILE% variable and therefore did not find the cmd.Bye,Alex
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