Jump to content

Passing drive letter variable to registery


Recommended Posts

Hi.

How do i convert the variable %%a to show up as a drive letter in the registery when i REG ADD it?

for %%a in (D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST %%a:\Documents and Settings\%USERNAME%

Set MYDOC=%%a:\Documents And Settings\%USERNAME%

SET MYREG=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders]

REG ADD "%MYREG%" /V "Personal" /T REG_EXPAND_SZ /D "%MYDOC%\My Documents" /F

Now in the registery it is showing up as %a:\Documents and Settings\UserName\My Documents :no:

How do i get it to show up as D:\Documents and Settings\UserName\My Documents?

Just need to get this sorted out and i think my goal will be complete. :D

Many Thanks

Worf.

Link to comment
Share on other sites


You could try it this way

@Echo Off && CLS && Color 5e && Mode 75,7 && Title %Appdata%

for %%a in (D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST set a=%a%\Documents And Settings goto Confirm

:Confirm

Set MYDOC=%Systemdrive%\Documents And Settings\%USERNAME%\My Documents

echo %MYDOC%

::SET MYREG=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders]

::REG ADD "%MYREG%" /V "Personal" /T REG_EXPAND_SZ /D "%MYDOC%" /F

set /p = Completed Script, Press Any Key To Close

Link to comment
Share on other sites

The only trouble is you are adding your information to the incorrect key!

Here is a long winded example which should help guide you

@ECHO OFF &SETLOCAL ENABLEEXTENSIONS
SET "PROFLOC1=" &CALL :GETDRVS
IF DEFINED PROFLOC1 GOTO :BEGINIT ELSE GOTO :ENDIT

:BEGINIT
SET USFKEY="HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"
SET SFKEY="HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
ECHO/REG ADD %USFKEY% /V Favorites /T REG_EXPAND_SZ /D "%PROFLOC1%\Favorites" /F
ECHO/REG ADD %USFKEY% /V "My Music" /T REG_EXPAND_SZ /D "%PROFLOC1%\My Documents\My Music" /F
ECHO/REG ADD %USFKEY% /V "My Pictures" /T REG_EXPAND_SZ /D "%PROFLOC1%\My Documents\My Pictures" /F
ECHO/REG ADD %USFKEY% /V Personal /T REG_EXPAND_SZ /D "%PROFLOC1%\My Documents" /F
ECHO/REG ADD %SFKEY% /V Favorites /D "%PROFLOC2%\Favorites" /F
ECHO/REG ADD %SFKEY% /V "My Music" /D "%PROFLOC2%\My Documents\My Music" /F
ECHO/REG ADD %SFKEY% /V "My Pictures" /D "%PROFLOC2%\My Documents\My Pictures" /F
ECHO/REG ADD %SFKEY% /V Personal /D "%PROFLOC2%\My Documents" /F

:ENDIT
ENDLOCAL &GOTO :EOF

:GETDRVS
FOR /F %%? IN ('MOUNTVOL^|FIND ":\"^|FINDSTR/IV "A:\\ %SYSTEMDRIVE%\\" 2^>NUL') DO (
IF ERRORLEVEL 0 (IF NOT DEFINED PROFLOC1 CALL :CHECKIT %%?))
GOTO :EOF

:CHECKIT
IF EXIST "%1%USERNAME%\MY DOCUMENTS" SET "PROFLOC1=%1%%USERNAME%%" &SET "PROFLOC2=%1%USERNAME%"
GOTO :EOF

<Edit>

I have deliberately added this as an edit so that you will see it!

When you have confirmed that it works, remove ECHO/ from the beginning of the eight lines and add >NUL to the end of them.

</Edit>

Edited by Yzöwl
Link to comment
Share on other sites

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