JSI Tip 9787. How can I create a custom drive icon in Windows XP?

I have scripted DriveIcon.bat to create a custom drive icon for any drive letter that you specify.

The syntax for using DriveIcon.bat is:

DriveIcon DriveLetter DriveIconPathIndex DriveLabel

Where:

DriveLetter        is the drive letter of the fixed or removable drive.

DriveIconPathIndex is a quoted string that contains the path to the file that contains the icon, a comma (,), 
                   and the icon index, starting with 0. The second row in column 1 is 1, the third row in column 1 is 2, etc.....

DriveLabel         is the drive label.
NOTE: If the drive is mounted, the new icon will take immediate effect. If the drive is not mounted, a restart is required.

DriveIcon.bat contains:

@echo off
if \{%3\}==\{\} @echo DriveIcon DriveLetter DriveIconPathIndex DriveLabel&goto :EOF
setlocal
set wrk=%1
set wrk=%wrk:"=%
set drv=%wrk:~0,1%
set icon=%2
set file=%icon:"=%
if "%file%" EQU "%icon%" @echo DriveIcon DriveLetter DriveIconPathIndex DriveLabel - "DriveIconPath,Index" required.&endlocal&goto :EOF
set work=%file:,= %
if "%work%" EQU "%file%" @echo DriveIcon DriveLetter DriveIconPathIndex DriveLabel - icon index missing.&endlocal&goto :EOF
for /f "Tokens=1" %%a in ('@echo %work%') do (
 set file=%%a
)
if not exist %file% @echo DriveIcon DriveLetter DriveIconPath DriveLabel - %file% NOT found.&endlocal&goto :EOF
if not exist %drv%:\ goto noar
set work=%icon%
set work=%icon:"=%
@echo \[autorun\]>%drv%:\autorun.inf
@echo ICON=%work%>>%drv%:\autorun.inf
attrib -a +R +S +H %drv%:\autorun.inf
:noar
set lbl=%3
set key1=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\%drv%\DefaultIcon
set key2=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DriveIcons\%drv%\DefaultLabel
@echo.
@echo REG ADD %key1% /Ve /T REG_SZ /F /D %icon%
REG ADD %key1% /Ve /T REG_SZ /F /D %icon%
@echo REG ADD %key2% /Ve /T REG_SZ /F /D %lbl%
REG ADD %key2% /Ve /T REG_SZ /F /D %lbl%
endlocal



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish