![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-24 21:51 |
47,812 topics / 349,910 posts / today 1 new / 48,262 members |
| DOS批处理 & 脚本技术(批处理室) » Hide the drive letters of my computer |
| Printable Version 2,589 / 15 |
| Floor1 darkkid | Posted 2009-04-13 06:44 |
| 初级用户 Posts 12 Credits 34 | |
|
```
@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 ] |
|
| Floor2 freeants001 | Posted 2009-04-13 06:48 |
| 中级用户 Posts 244 Credits 330 From 湖北 | |
| Floor3 yishanju | Posted 2009-04-13 07:19 |
| 银牌会员 Posts 1,357 Credits 1,488 | |
|
Never did I dream that I could write such a long piece of code
|
|
| Floor4 HAT | Posted 2009-04-13 07:32 |
| 版主 Posts 5,017 Credits 9,023 | |
|
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. |
|
| Floor5 netbenton | Posted 2009-04-13 07:49 |
| 银牌会员 Posts 752 Credits 1,916 From 广西 | |
|
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 ] |
|
| Floor6 darkkid | Posted 2009-04-13 08:08 |
| 初级用户 Posts 12 Credits 34 | |
|
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 ] |
|
| Floor7 zh159 | Posted 2009-04-13 10:26 |
| 金牌会员 Posts 1,467 Credits 3,687 | |
|
Collected a long time ago
|
|
| Floor8 wxcute | Posted 2009-04-13 11:00 |
| 中级用户 Posts 211 Credits 458 | |
|
Reply to zh159:
It's really an honor that someone has bookmarked this code. Truly, truly honored. |
|
| Floor9 netbenton | Posted 2009-04-13 20:39 |
| 银牌会员 Posts 752 Credits 1,916 From 广西 | |
|
Not bad, newbie, add points,
Actually, I'm not that "old" either. Hehe |
|
| Floor10 dnntgmfd | Posted 2009-04-13 23:16 |
| 初级用户 Posts 52 Credits 85 From 湘乡 | |
|
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
|
|
| Floor11 HAT | Posted 2009-04-14 00:14 |
| 版主 Posts 5,017 Credits 9,023 | |
|
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. |
|
| Floor12 tireless | Posted 2009-04-14 02:14 |
| 银牌会员 Posts 1,122 Credits 2,025 | |
|
You can use gpupdate.exe /force instead of restarting the explorer.exe process.
|
|
| Floor13 darkkid | Posted 2009-04-14 10:23 |
| 初级用户 Posts 12 Credits 34 | |
|
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 |
|
| Floor14 HAT | Posted 2009-04-15 02:36 |
| 版主 Posts 5,017 Credits 9,023 | |
|
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.
|
|
| Floor15 darkkid | Posted 2009-04-15 02:52 |
| 初级用户 Posts 12 Credits 34 | |
|
Entering double quotes is at least okay here, analyze specific problems specifically, we'll calculate then.
|
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |