Jump to content

Recommended Posts

Posted

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 =%%i

SET 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,2

HOMEPATH=~-2,0

HOMEPATH =D:\Alexander

Any 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


Posted

@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

Posted

Ok heres the drill

I set my user folder this way...

CMDLINES.TXT

REGEDIT /S HKCU.reg

HKCU.REG

Windows 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 joke

Notice the double backslash, manupulate your string to have the double backslash and try again...

Roger

edit if that is not what your looking for, please post some more information on what your trying to do...

Posted

this is what i used to use to get values form the registry

SET 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=SourcePath
SET HPID=Identifier

for /f "skip=4 tokens=2*" %%a in ('reg query %KEY1% /v "%XPCD%"') do set XPCD=%%b
for /f "skip=4 tokens=2*" %%a in ('reg query %KEY2% /v "%HPID%"') do set HPID=%%b

Posted

Hi !

@Alanoll

Thanks, 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

Posted

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 /f

What 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"     or
cmd /c %USERPROFILE%\home.cmd       or
cmd /c %USERPROFILE%\\home.cmd      or
cmd /c %%USERPROFILE%%\\home.cmd      or
cmd /c %%USERPROFILE%%\home.cmd      or
cmd /c "%%USERPROFILE%%\home.cmd"      or

without the cmd /c ....

Nothing works. The key does not get written to the registry :):rolleyes::D

Alex

Posted

pah ! :rolleyes:

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" /f

and 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

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