|
darkkid
初级用户
 
积分 34
发帖 12
注册 2009-2-18
状态 离线
|
『楼 主』:
隐藏我的电脑的盘符
使用 LLM 解释/回答一下
@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
注释一下,核心代码就是3条for语句
第一条用来小写转换为大写
第二条用来判断是否重复输入了
第三条用来为每个盘符赋值的
特别感谢netbenton,和那位给出个示例代码的大哥
非常感谢netbenton你,令我感悟到了新一步
回复用gpupdate那个,我的杀毒软件会警报啊。。。
============版主请看我的跟帖
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 ]
此帖被 +8 点积分 点击查看详情 评分人:【 HAT 】 | 分数: +4 | 时间:2009-4-13 07:30 | 评分人:【 netbenton 】 | 分数: +4 | 时间:2009-4-13 20:38 |
|
|
|
2009-4-13 06:44 |
|
|
freeants001
中级用户
  
积分 330
发帖 244
注册 2006-4-14 来自 湖北
状态 离线
|
|
2009-4-13 06:48 |
|
|
yishanju
银牌会员
     [b]看你妹啊[/b]
积分 1488
发帖 1357
注册 2006-5-20
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
做梦都没想能写这么长的代码
Never did I dream that I could write such a long piece of code
|

有问题请发论坛或者自行搜索,再短消息问我的统统是SB |
|
2009-4-13 07:19 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
新人发帖,加分鼓励。
建议楼主可以尝试把这个300多行的代码缩短到100行以内。
New user post, add points for encouragement.
It is suggested that the original poster can try to shorten this code of more than 300 lines to within 100 lines.
|

 |
|
2009-4-13 07:32 |
|
|
netbenton
银牌会员
     批处理编程迷
积分 1916
发帖 752
注册 2008-12-28 来自 广西
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
这样可以省掉多个if ... goto 和多个for ...判断是否已经输入过
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 "
if not "!str: %drv% =!"=="!str!" (
if not "!ain: %drv% =!"=="!ain!" (set "ain=%ain% %drv% "&goto :part%drv%)
)
盘符与数的对应关系为:
a 1
b 2
c 4
d 8
e 16
f 32
g 64
h 128
...
这样可以得到对应数值:
set n=1
for %%a in (%str%) do if "%drv%"=="%%a" (goto :ok) else (set/a n=n+n)
:ok
再想办法转成16进制,可省去多个分支的做法。
用上面的方法,可把代码控制在50行以内
楼主可以试一下
Last edited by netbenton on 2009-4-13 at 06:15 ]
This can save multiple if...goto and multiple for...judgments to see if it has been input before
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 "
if not "!str: %drv% =!"=="!str!" (
if not "!ain: %drv% =!"=="!ain!" (set "ain=%ain% %drv% "&goto :part%drv%)
)
The correspondence between drive letters and numbers is:
a 1
b 2
c 4
d 8
e 16
f 32
g 64
h 128
...
In this way, the corresponding value can be obtained:
set n=1
for %%a in (%str%) do if "%drv%"=="%%a" (goto :ok) else (set/a n=n+n)
:ok
Then try to convert it to hexadecimal, which can save the practice of multiple branches.
With the above method, the code can be controlled within 50 lines
The 楼主 can give it a try
Last edited by netbenton on 2009-4-13 at 06:15 ]
|

精简
=> 个人 网志  |
|
2009-4-13 07:49 |
|
|
darkkid
初级用户
 
积分 34
发帖 12
注册 2009-2-18
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
回netbenton
明白你的想法了。
现阶段的我对你的代码理解起来有困难,等我慢慢参透一下,
Last edited by darkkid on 2009-4-13 at 08:26 ]
Back to netbenton
Got your idea.
At the current stage, it's difficult for me to understand your code. I'll take my time to figure it out.
Last edited by darkkid on 2009-4-13 at 08:26 ]
|
|
2009-4-13 08:08 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
N久前收藏的
@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%,共个盘。
::换成十六进制
: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
Collected a long time ago
@echo off
:inp
cls
set Drv=
echo Enter the number "0" to unhide, enter several letters to hide the corresponding disks.
set/p Drv=Enter disk (e.g.: EaF)-
if "%Drv%"=="" goto :inp
if %Drv%==0 set TT=00&goto :hidrv
::Convert lowercase to uppercase and output in order and remove duplicates
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
)
)
::Display
echo.
echo The disks to hide are %Drv%, total disks.
::Convert to hexadecimal
:reg16
setlocal enableDelayedExpansion
call :A %n10%
::Registry binary value expression
::T3 to 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
::Hide disk
::-=Core code=-
:hidrv
set TT=%TT%000000
reg add HKCU\SoftWare\Microsoft\Windows\CurrentVersion\Policies\Explorer /v NoDrives /t REG_BINARY /d %TT:~,8% /f
echo End explorer process to take effect. Press any key to end and open My Computer to view
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
::Call label
: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
|

 |
|
2009-4-13 10:26 |
|
|
wxcute
中级用户
  
积分 458
发帖 211
注册 2006-7-26
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
回复 zh159:
这个代码居然有人收藏,真是荣幸、荣幸之至。
Reply to zh159:
It's really an honor that someone has bookmarked this code. Truly, truly honored.
|

┌───────┐
├→学习→实践→┤
└───────┘ |
|
2009-4-13 11:00 |
|
|
netbenton
银牌会员
     批处理编程迷
积分 1916
发帖 752
注册 2008-12-28 来自 广西
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
改得不错,新人,加分,
其实偶也“旧”不了多少。呵呵
Not bad, newbie, add points,
Actually, I'm not that "old" either. Hehe
|

精简
=> 个人 网志  |
|
2009-4-13 20:39 |
|
|
dnntgmfd
初级用户
 
积分 85
发帖 52
注册 2009-1-10 来自 湘乡
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
大家可以试着把你的系统盘隐藏,,,有很好的效果,,,反正我试过了,,,,
就连开网页都打不开了,,有意向的朋友可以
You can try to hide your system disk... It has a very good effect... Anyway, I have tried it... Even opening web pages can't be opened. Friends who are interested can
|
|
2009-4-13 23:16 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
粗略的看了一遍,提出几个疑问:
:: 说明,本批处理的功能是隐藏在Windows资源管理器中的磁盘盘符,一定程度上保护了个人的隐私。任何人都能通过记事本来编辑这个批处理,使得它的功能更加强大,效率更加高。小民,2009年4月12日,为学习好批处理,在此分享。
@echo off&setlocal enabledelayedexpansion
: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
set n=1
:HIDEDRV
::::::::::::除了echo off前面的那个@,后面还使用了这么多@,是为了过瘾?还是为了别的什么?
@cls
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%%
::::::::::::给下面的if加个/i开关即可忽略大小写,上面的for是不是多余的?
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)
goto HIDEDRV
:next
set needhidedrv=%needhidedrv%%drv%
set /a value=value+n
goto HIDEDRV
:exec
@cls
reg delete HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer /f /v NoDrives
::::::::::::reg add命令采用的是覆盖写入的方法,上面的reg delete是不是多余的?
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.exe
@echo 操作完成,按任意键退出
pause>nul
exit&exit
A rough look-through, and a few questions are raised:
:: Explanation, the function of this batch processing is to hide the disk drive letters in Windows Explorer, which protects personal privacy to a certain extent. Anyone can edit this batch processing with Notepad to make its function more powerful and more efficient. Xiaomin, April 12, 2009, sharing here for learning batch processing well.
@echo off&setlocal enabledelayedexpansion
:setvar
set needhidedrv=Not yet entered.
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
set n=1
:HIDEDRV
::::::::::::Besides the @ before echo off, so many @ are used. Is it for fun? Or something else?
@cls
set drv=endinput
@echo The drive letters that have been entered to hide:
@echo ===============================================================================
@echo.
@echo.
@echo %needhidedrv%
@echo.
@echo.
@echo ===============================================================================
@echo.
@echo For example, if you need to hide C drive, enter c or C, press Enter. If you need to enter multiple drive letters, continue input. If you want to complete input, just press Enter. Enter all to hide all, press Enter to cancel hide.
@echo.&@echo.&@echo.
set /p drv=Please input:
::::::::::::If user input a double quote, code abnormal.
if "%drv%"=="endinput" goto exec
if "%drv%"=="endinput" goto exec
if "%needhidedrv%"=="Not yet entered." set needhidedrv=
for %%i in (%str%) do call set drv=%%drv:%%i=%%i%%
::::::::::::Add /i to below if to ignore case. Above for redundant?
for %%i in (%needhidedrv%) do (if "%drv%"=="%%i" goto HIDEDRV)
for %%i in (%str%) if "%drv%"=="%%i" (set needhidedrv's %%drv) set /a value=value+n
goto next
:next
set needhidedrv=%needhidedrv%%drv%
exec@cls
reg delete HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer /f /v NoDrives
::::::::::::reg add overwrite. Above reg delete redundant?
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.exe
@echo Operation complete, press any key exit
pause>nul
exit&exit
|

 |
|
2009-4-14 00:14 |
|
|
tireless
银牌会员
    
积分 2025
发帖 1122
注册 2007-9-5
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
可以用 gpupdate.exe /force 代替重启 explorer.exe 进程。
You can use gpupdate.exe /force instead of restarting the explorer.exe process.
|
|
2009-4-14 02:14 |
|
|
darkkid
初级用户
 
积分 34
发帖 12
注册 2009-2-18
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
修正了个小错误,把set n=1放到了:hidedrv之外了,导致隐藏多个盘符时,除第一个盘符外的都赋值错误,也在此谢谢tireless
以下回版主HAT
首先关于@这个符号,我的代码当中可有可没,嫌弃它碍眼就删吧,因为我在第一行已经输入了echo off这句。如果在每句之前加这个@号,其作用等于echo off。
你所谓的输入异常应该是在第一次输入的时候吧,显示为echo 消息为关闭?其实不是大问题,不只:,所有非abcdefg。。。。。。的字符串都会出现的,完全不理会都没问题的,主要是我开始为了显示"暂无输入"的后遗症,当我清空了显示列表后,echo无法显示空字符串而已
我那句转换大小写,首先,嗯,我说我有点新人吧,我不知道if的这个参数,这么好用的东西谢谢版主教导,如果想用这个参数,把我str的大写A B C D。。。。。改为a b c d。。。。。就能运行,只是运行时,没那么好看,显示的都是小写,不改了,我喜欢漂亮一点的。
最后那个无它,也是不知道而已
现在要上学,上网不方便,周末回家再搞
Fixed a small error by moving set n=1 outside of :hidedrv, which caused incorrect assignments for all but the first drive when hiding multiple drives. Thanks to tireless here as well.
The following is in response to moderator HAT:
First, regarding the @ symbol, it's optional in my code. You can delete it if you find it obtrusive since I already have echo off on the first line. Adding @ before each line is equivalent to echo off.
The input anomaly you mentioned should be when entering for the first time, showing echo message as off? Actually, it's not a big deal. All strings other than abcdefg... will have this issue, and it's completely fine to ignore it. It's mainly a legacy from my initial display of "No input yet". When I clear the display list, echo can't display an empty string.
Regarding my case conversion, well, I said I'm a bit of a newbie. I didn't know about this parameter in if. Thanks to the moderator for the instruction. If I want to use this parameter, changing my str's uppercase A B C D... to lowercase a b c d... will make it run, but it won't look as nice when running, showing all lowercase. I won't change it; I prefer it to be nicer looking.
Finally, the last "no it" is just because I didn't know.
Now I need to go to school, and internet access is not convenient. I'll work on it again when I get home on the weekend
|
|
2009-4-14 10:23 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 14 楼』:
Re 13楼
使用 LLM 解释/回答一下
关于用户输入一个双引号的问题,等你以后遇到无法忽略它的情况再回来讨论吧,现在你坚持这样用就这样用吧。
Regarding the issue of users entering a double quote, come back to discuss it when you encounter a situation where you can't ignore it in the future. For now, just use it as you insist.
|

 |
|
2009-4-15 02:36 |
|
|
darkkid
初级用户
 
积分 34
发帖 12
注册 2009-2-18
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
输入双引号起码这里没事,具体问题具体分析,到时再算
Entering double quotes is at least okay here, analyze specific problems specifically, we'll calculate then.
|
|
2009-4-15 02:52 |
|