方法一:- @echo off&setlocal enabledelayedexpansion
- title 驱动器隐藏
- :setvar
- set needhidedrv=暂未输入。
- 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 已输入的需要隐藏的驱动器:
- echo ===============================================================================
- echo.
- echo.
- echo %needhidedrv%
- echo.
- echo.
- echo ===============================================================================
- echo.
- echo 例如需隐藏C盘,请输入c或C,回车。如果需输入多个盘符就继续输入,如果想完成输入就直接按下回车,输入all为隐藏全部,在初始状态下直接回车则取消隐藏
- echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.
- set /p drv=请输入:
- if "%drv%"=="endinput" goto exec
- if "%drv%"=="all" set value=0X3FFFFFF&goto exec
- if "%needhidedrv%"=="暂未输入。" 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=暂未输入。
- 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 操作完成,按任意键退出
- pause>nul
- exit&exit
复制代码 方法二:- @echo off
-
- :inp
- cls
- set Drv=
- echo 输入数字“0”取消隐藏,输入若干字母隐藏相应的磁盘。
- set/p Drv=输入磁盘(如:EaF)-
-
- if "%Drv%"=="" goto :inp
- if %Drv%==0 set TT=00&goto :hidrv
-
- ::小写换大写顺序输出并剔除重复
- set mat=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
- for %%d in (%mat%) do (
- call set _%%d=
- )
- :lp
- if not defined _%Drv:~,1% set "_%Drv:~,1%=1"
- set "Drv=%Drv:~1%"
- if defined Drv goto lp
- set n=1
- set n10=
- set Dnum=
- for %%m in (%mat%) do (
- call :setn n
- if defined _%%m (
- call :sshow %%m Drv Dnum n2 n10
- )
- )
-
- ::显示
- echo.
- echo 要隐藏的磁盘有%Drv%,共[%Dnum%]个盘。
-
- ::换成十六进制
- :reg16
- setlocal enableDelayedExpansion
- call :A %n10%
-
- ::注册表二进制数值表达方式
- ::T3换BIN
- set TT=
- :bi
- set/a x+=1
- set Tn=0%T3:~-2%
- set Tn=!Tn:~-2!
- set T3=%T3:~,-2%
- set TT=!TT!!Tn!
- if not #%T3%==# goto :bi
-
- ::隐藏磁盘
- ::-=核心代码=-
- :hidrv
- set TT=%TT%000000
- reg add HKCU\SoftWare\Microsoft\Windows\CurrentVersion\Policies\Explorer /v NoDrives /t REG_BINARY /d %TT:~,8% /f
-
- echo 结束explorer进程生效。按任意键结束并打开我的电脑查看
- pause>nul
- taskkill /f /im explorer.exe>nul
- endlocal
- start/min "" explorer "%~dp0"
- start explorer ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}
-
- ping -n 3 127.1>nul
- goto :eof
-
- ::调用标签
- :sshow
- set %2=%Drv%%1
- set/a %3+=1
- set/a %4=n/2
- set/a %5+=n2
- goto :eof
- :setn
- set/a %1*=2
- goto :eof
- :A
- set str=0123456789ABCDEF
- set T1=%1
- SET T3=
- :B
- set/A T2=T1%%16
- SET T2=!str:~%t2%,1!
- SET/A T1=%T1%/16
- SET T3=%T2%%T3%
- IF %T1%==0 GOTO :EOF
- GOTO B
复制代码 原文地址:http://www.cn-dos.net/forum/viewthread.php?tid=46914 |