```
@echo off&setlocal enabledelayedexpansion
title Drive Hiding
:setvar
set needhidedrv=Not entered yet.
set value=0
set str=A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
:HIDEDRV
cls
set n=1
set drv=endinput
echo The drives that need to be hidden that have been entered:
echo ===============================================================================
echo.
echo.
echo %needhidedrv%
echo.
echo.
echo ===============================================================================
echo.
echo For example, if you need to hide drive C, please enter c or C, then press Enter. If you need to enter multiple drive letters, continue to enter. If you want to complete the input, just press Enter directly. Enter all to hide all. In the initial state, pressing Enter directly will cancel the hiding
echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.
set /p drv=Please enter:
if "%drv%"=="endinput" goto exec
if "%drv%"=="all" set value=0X3FFFFFF&goto exec
if "%needhidedrv%"=="Not entered yet." set needhidedrv=
for %%i in (%str%) do call set drv=%%drv:%%i=%%i%%
for %%i in (%needhidedrv%) do (if "%drv%"=="%%i" goto HIDEDRV)
for %%i in (%str%) do if "%drv%"=="%%i" (goto :next) else (set /a n=n+n)
if "%needhidedrv%"=="" set needhidedrv=Not entered yet.
goto HIDEDRV
:next
set needhidedrv=%needhidedrv%%drv%
set /a value=%value%+%n%
goto HIDEDRV
:exec
reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer /f /v NoDrives /t REG_DWORD /d %value%
taskkill /f /im explorer.exe >nul & start explorer &cls
echo Operation completed, press any key to exit
pause>nul
exit&exit
```
Note: The core code is three for statements. The first one is used to convert lowercase to uppercase. The second one is used to judge whether the input is repeated. The third one is used to assign a value to each drive letter.
Special thanks to netbenton and the elder brother who gave an example code.
Thank you very much, netbenton. You made me realize a new step.
Regarding replying with gpupdate, my antivirus software will give an alarm...
============Moderator, please see my follow-up post
[ Last edited by darkkid on 2009-4-15 at 22:07 ]
@echo off&setlocal enabledelayedexpansion
title Drive Hiding
:setvar
set needhidedrv=Not entered yet.
set value=0
set str=A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
:HIDEDRV
cls
set n=1
set drv=endinput
echo The drives that need to be hidden that have been entered:
echo ===============================================================================
echo.
echo.
echo %needhidedrv%
echo.
echo.
echo ===============================================================================
echo.
echo For example, if you need to hide drive C, please enter c or C, then press Enter. If you need to enter multiple drive letters, continue to enter. If you want to complete the input, just press Enter directly. Enter all to hide all. In the initial state, pressing Enter directly will cancel the hiding
echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.
set /p drv=Please enter:
if "%drv%"=="endinput" goto exec
if "%drv%"=="all" set value=0X3FFFFFF&goto exec
if "%needhidedrv%"=="Not entered yet." set needhidedrv=
for %%i in (%str%) do call set drv=%%drv:%%i=%%i%%
for %%i in (%needhidedrv%) do (if "%drv%"=="%%i" goto HIDEDRV)
for %%i in (%str%) do if "%drv%"=="%%i" (goto :next) else (set /a n=n+n)
if "%needhidedrv%"=="" set needhidedrv=Not entered yet.
goto HIDEDRV
:next
set needhidedrv=%needhidedrv%%drv%
set /a value=%value%+%n%
goto HIDEDRV
:exec
reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer /f /v NoDrives /t REG_DWORD /d %value%
taskkill /f /im explorer.exe >nul & start explorer &cls
echo Operation completed, press any key to exit
pause>nul
exit&exit
```
Note: The core code is three for statements. The first one is used to convert lowercase to uppercase. The second one is used to judge whether the input is repeated. The third one is used to assign a value to each drive letter.
Special thanks to netbenton and the elder brother who gave an example code.
Thank you very much, netbenton. You made me realize a new step.
Regarding replying with gpupdate, my antivirus software will give an alarm...
============Moderator, please see my follow-up post
[ Last edited by darkkid on 2009-4-15 at 22:07 ]




