China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-01 14:45
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to safely delete hardware using batch processing? View 2,908 Replies 9
Original Poster Posted 2005-12-01 16:31 ·  中国 广东 广州 白云区 电信
荣誉版主
★★★
Credits 718
Posts 313
Joined 2005-09-26 00:00
20-year member
UID 42844
Gender Male
Status Offline
Recently, too many people are printing resumes. My friend's computer keeps inserting USB drives, MP3s, and keeps clicking "Safely Remove Hardware" from the taskbar...
I want to put the batch file shortcut in the Quick Launch bar and just click it. Can it be done with a batch file? What's the code?
Thanks :>
Floor 2 Posted 2005-12-01 16:54 ·  中国 山西 临汾 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re 220110:

The batch processing solution hasn't been thought of yet. Just in my memory, when plugging and unplugging USB drives and other devices directly under XP, there is no alarm prompt. It might need some settings, which is unknown. In addition, if you really need to safely remove, you can left - click the hardware icon, and then it only takes two mouse clicks to remove the specified device.
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 3 Posted 2005-12-01 19:50 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
D◎$ Fαп
Credits 4,562
Posts 1,883
Joined 2004-01-19 00:00
22-year member
UID 15812
Gender Male
From 广东广州
Status Offline
Re 220110 and willsort:

You can use third-party tools Unlocker and unplug to quickly unplug USB drives in batch processing.

The following content is quoted from http://blog.dream4ever.org/venchia/

Method 2
For problems that cannot be solved in a graphical interface like Windows, we need to try to solve them in the dark command line state. First, download the unplug.rar software, extract it, and then run the cmd command to open the command prompt window. Then use the dir command to enter the directory where the unplug.exe file is located. Here, taking stopping the H drive (assuming the H drive is the flash drive location) as an example, enter the command unplug H:. Of course, a more efficient method is to make a batch processing to get it done. (Modify the parameter "d:\unplug" after the cd command in the script to the directory where unplug.exe is located, and "h" to the drive letter occupied by the flash drive), save the following script as usb.bat, and double-click it when needed. If you specify a hot key, you can uninstall it with one click!
The usb.bat is as follows

@echo off
cd d:\unplug
unplug h:

If unplug can't get it done, then it's time for unlocker to come into play

Method 3
Now cooperate with the /s command line of unlocker, first unlock the device drive letter to be uninstalled, then unplug, basically it can be uninstalled at one time.

Attach a script

@echo off 

REM Feature string of IBM UDISK 3 USB Mass Storage Device\IC25N020 ATMR04-0 USB Device
echo #|unplug|findstr " USB Mass Storage Device\IC25N020">%temp%\tmpout.txt
for /f "usebackq delims= tokens=1,2,3" %%i in (%temp%\tmpout.txt) do (
"<path>\Unlocker.exe" %%j /s
unplug %%i |findstr "OK."
if errorlevel 1 pause
)


In this script, if it is still detected that it cannot be uninstalled, if it occurs, run pause to prompt, and if it flashes by, you can pull out the device.

Instructions:
1, Replace with the feature string of your USB drive, use unplug to check
2, Replace the location of unlocker, it is recommended to put both unlocker and unplug in the search path.
3, Since unplug returns errorlevel as 1 regardless of whether unplug is successful or not, so use findstr to judge whether unplug is successful.


Software download used

unplug.rar
Unlocker.v1.66.GR.rar (1.66 green version)
Unlocker.v1.7.3.rar
----====≡≡≡≡ 我的至爱,永远是MSDOS!≡≡≡≡====----
Floor 4 Posted 2005-12-01 22:35 ·  中国 广东 广州 白云区 电信
荣誉版主
★★★
Credits 718
Posts 313
Joined 2005-09-26 00:00
20-year member
UID 42844
Gender Male
Status Offline
First of course, thank two friends! Especially little JONG, who also brought up the link address! Thanks!

I once tried to end related processes by using processes, but didn't find related processes. Only after selecting "Safely Remove Hardware" did a "rundll32.exe" appear. It didn't work.
Floor 5 Posted 2005-12-01 22:40 ·  中国 广东 广州 白云区 电信
荣誉版主
★★★
Credits 718
Posts 313
Joined 2005-09-26 00:00
20-year member
UID 42844
Gender Male
Status Offline
I tried the second plan provided by Xiao JONG, and indeed it flashed by without a prompt. But by checking through hardware management, this hardware is still enabled, so I still dare not remove it casually. After all, it's the client's stuff, and it's not good if it's damaged... Let's all work harder!
Floor 6 Posted 2005-12-02 23:07 ·  中国 辽宁 锦州 中移铁通
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
21-year member
UID 40733
Gender Male
Status Offline
Try MS's own thing, DevCon.

The DevCon command-line utility replaces Device Manager
Summary
The DevCon utility is a command-line utility that replaces Device Manager. With DevCon, you can enable, disable, restart, update, delete, and query a single device or a group of devices. DevCon also provides information related to driver developers that isn't visible in Device Manager.
Link: http://support.microsoft.com/kb/311272/zh-cn
  ☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul

Floor 7 Posted 2005-12-03 20:05 ·  中国 广东 广州 白云区 电信
荣誉版主
★★★
Credits 718
Posts 313
Joined 2005-09-26 00:00
20-year member
UID 42844
Gender Male
Status Offline
DEVCON, a very powerful command, saw many, many things.

Playing around....
Floor 8 Posted 2005-12-07 11:13 ·  中国 安徽 芜湖 电信
高级用户
★★★
Credits 866
Posts 415
Joined 2005-12-04 11:19
20-year member
UID 46459
Status Offline
It's still quite advanced for me, I still need to learn a lot!

Right-click the USB drive, and "Eject" is also okay.
Floor 9 Posted 2005-12-07 17:37 ·  中国 广东 广州 白云区 电信
荣誉版主
★★★
Credits 718
Posts 313
Joined 2005-09-26 00:00
20-year member
UID 42844
Gender Male
Status Offline
Originally posted by htysm at 2005-12-7 11:13:
Right-click the USB drive and select "Eject" is also okay.


This is also okay, but still troublesome.
If I create a shortcut and assign a function key; then I can just press the key once.
Alas, limited skills, still can't figure out the DEVCON command, please everyone help again. Thanks
Floor 10 Posted 2005-12-07 20:01 ·  中国 山东 济南 移动
钻石会员
★★★★★
Credits 10,051
Posts 3,040
Joined 2002-11-11 00:00
23-year member
UID 223
Gender Male
Status Offline
In the "Device Manager", expand the "Disk Drives" option, right-click the USB flash drive, open the "Properties" dialog box, select the "Policies" tab, and choose "Optimize for quick removal".
简单就是美
Forum Jump: