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

Jerold Schulman

October 5, 2005

1 Min Read
ITPro Today logo in a gray background | ITPro Today

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 offif {%3}=={} @echo DriveIcon DriveLetter DriveIconPathIndex DriveLabel&goto :EOFsetlocalset wrk=%1set wrk=%wrk:"=%set drv=%wrk:~0,1%set icon=%2set file=%icon:"=%if "%file%" EQU "%icon%" @echo DriveIcon DriveLetter DriveIconPathIndex DriveLabel - "DriveIconPath,Index" required.&endlocal&goto :EOFset work=%file:,= %if "%work%" EQU "%file%" @echo DriveIcon DriveLetter DriveIconPathIndex DriveLabel - icon index missing.&endlocal&goto :EOFfor /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 :EOFif not exist %drv%: goto noarset work=%icon%set work=%icon:"=%@echo [autorun]>%drv%:autorun.inf@echo ICON=%work%>>%drv%:autorun.infattrib -a +R +S +H %drv%:autorun.inf:noarset lbl=%3set key1=HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerDriveIcons%drv%DefaultIconset key2=HKLMSOFTWAREMicrosoftWindowsCurrentVersionExplorerDriveIcons%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



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like