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-07-02 17:56
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to judge that a USB flash drive has been inserted and automatically copy all the contents View 15,631 Replies 40
Floor 16 Posted 2007-02-02 07:18 ·  中国 广东 广州 番禺区 广州海之光通讯技术有限公司
初级用户
★★
Credits 138
Posts 55
Joined 2007-02-02 05:54
19-year member
UID 78395
Gender Male
Status Offline
I also come to study~!
What I want is to display and prompt that the copy is successful!
It's from the folder Copy to the USB drive...
If H: is inserted, copy CP to H:
If G: is inserted, copy CP to G:
Do two at once. Just both prompts.
If U_DISK is not found, don't copy.
Hehe. LZ, help make a simple one. No need for any installation, etc.
Brothers, help study it...
Floor 17 Posted 2007-02-02 08:30 ·  中国 辽宁 本溪 联通
银牌会员
★★★
Credits 1,212
Posts 464
Joined 2006-12-13 21:11
19-year member
UID 73417
Gender Male
Status Offline
Extra points~

But it seems that it cannot be successfully terminated. I wonder if the same is true for everyone here?
Floor 18 Posted 2007-02-02 11:21 ·  中国 浙江 电信
中级用户
★★
Credits 385
Posts 156
Joined 2007-01-19 02:32
19-year member
UID 76955
Gender Male
Status Offline
LZ, I wonder if a new user like me can say something.
It seems there is an imprecise parameter in the code of your copy.cmd.
xcopy /e /y %%i\*.* c:\copy >nul 2>nul
I think /c should be added.

/C Continue copying even if there are errors.
Floor 19 Posted 2007-02-02 11:22 ·  中国 浙江 电信
中级用户
★★
Credits 385
Posts 156
Joined 2007-01-19 02:32
19-year member
UID 76955
Gender Male
Status Offline
I quite admire the楼主's IDEA, and even more admire everyone's abilities.
Floor 20 Posted 2007-02-02 11:27 ·  中国 浙江 电信
中级用户
★★
Credits 385
Posts 156
Joined 2007-01-19 02:32
19-year member
UID 76955
Gender Male
Status Offline
The role of deleting this is to delete the "IsShortcut" value under the "lnkfile" and "piffile" keys in the HKEY_CLASSES_ROOT registry key. The ">nul 2>nul" part is used to redirect the standard output and standard error output to the null device, that is, to make the execution of these commands not display any output on the screen.
Floor 21 Posted 2007-03-12 09:48 ·  中国 广东 东莞 电信
新手上路
Credits 17
Posts 9
Joined 2007-03-12 09:25
19-year member
UID 81491
Gender Male
Status Offline
Floor 22 Posted 2007-03-15 06:53 ·  中国 广东 东莞 电信
初级用户
Credits 50
Posts 21
Joined 2007-03-13 08:06
19-year member
UID 81579
Gender Male
Status Offline
Originally posted by gene771771 at 2006-11-29 12:29 AM:
There is a fairy asking me to write a batch script. First, judge whether the USB flash drive is inserted. If it is inserted, automatically copy all contents to the hard disk, and it also needs to be sneaky... I thought it over and over again, but still couldn't ...

There are USB flash drive robbers on the Internet, and there are also flash drive snoops
which can realize all your requirements and run completely hidden.
Attachments
1.PNG
Floor 23 Posted 2007-03-19 01:10 ·  中国 湖南 长沙 电信
新手上路
Credits 9
Posts 5
Joined 2007-03-19 00:24
19-year member
UID 82181
Gender Male
Status Offline
Using PING, will it occupy too many system resources and have time limits? Using SLEEP also has time limits.

For example, if I change it to copying files from the computer to a mobile device, then it's not very practical. I want the COPY to be 100% successful, regardless of the time length.

If it can be resident in memory without using third-party software, that would be really great.

By the way, I'm asking about how to implement this in C language (I shouldn't ask C here, sorry)
Floor 24 Posted 2007-05-03 11:07 ·  中国 安徽 芜湖 电信
中级用户
★★
Credits 247
Posts 123
Joined 2007-04-17 06:29
19-year member
UID 85468
Gender Male
Status Offline
There are quite a lot of replies, which is a hot topic. It's written too complicatedly.
Floor 25 Posted 2007-05-03 12:41 ·  中国 广东 广州 番禺区 电信
中级用户
★★
脚本爱好者
Credits 238
Posts 93
Joined 2007-03-11 13:38
19-year member
UID 81417
Gender Male
From GZ
Status Offline
In fact, this work can be done with VBS and hidden (as in the following example). The advantage of this script is that it can successfully copy files for USB drives identified as mobile hard drive types.

1. Monitor all newly added drives and copy all files from new drives to the D drive

'Monitor inserted USB drives or mobile hard drives at any time, and if there are any, automatically copy all files in them to d:\Tmp
'Change fso.CopyFile to fso.CopyFolder to copy folders
'Note: Files or folders with hidden and system attributes are all copied
'Overwrite true, not overwrite false. Files and folders with read-only attributes cannot be overwritten
'If there are multiple new drive letters, the files in each drive are copied

Set fso = CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colEvents = objWMIService.ExecNotificationQuery ("Select * From __InstanceOperationEvent Within 5 Where " _
& "TargetInstance isa 'Win32_LogicalDisk'")
Do While True
Set objEvent = colEvents.NextEvent
If objEvent.TargetInstance.DriveType = 3 Then
If objEvent.Path_.Class = "__InstanceCreationEvent" Then
NewDri = objEvent.TargetInstance.DeviceId
fso.CopyFile NewDri & "\*","d:\Tmp\",true
End If
End If
Loop


2. Monitor newly added drives and only copy all files in the first partition to the D drive

Dim NewDri(9)
Set fso = CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colEvents = objWMIService.ExecNotificationQuery ("Select * From __InstanceOperationEvent Within 5 Where " _
& "TargetInstance isa 'Win32_LogicalDisk'")
Do While True
Set objEvent = colEvents.NextEvent
If objEvent.TargetInstance.DriveType = 3 Then
If objEvent.Path_.Class = "__InstanceCreationEvent" Then
i=i + 1
NewDri(i) = objEvent.TargetInstance.DeviceId
fso.CopyFile NewDri(i) & "\*","d:\Tmp\",true
End If
End If
Loop
Floor 26 Posted 2007-05-03 12:52 ·  中国 湖北 武汉 联通
中级用户
★★
Credits 245
Posts 103
Joined 2006-06-30 00:00
20-year member
UID 57801
Gender Male
Status Offline
Now we need to focus on both BAT and VBS, and do both well...
AXI, I admire you so much that it's like a continuous stream of rushing water...
Floor 27 Posted 2007-05-16 09:42 ·  中国 广东 珠海 电信
新手上路
Credits 2
Posts 1
Joined 2007-05-16 09:20
19-year member
UID 88669
Gender Male
Status Offline
How to record the content copied after inserting the USB flash drive, specifically what the name and content are
Floor 28 Posted 2007-06-06 10:34 ·  中国 河南 郑州 教育网
新手上路
Credits 2
Posts 1
Joined 2007-06-06 10:12
19-year member
UID 90407
Gender Male
Status Offline
You should directly post the source code for easy communication.
Floor 29 Posted 2007-06-12 10:16 ·  中国 山东 滨州 电信
新手上路
Credits 0
Posts 1
Joined 2007-06-11 23:05
19-year member
UID 91014
Gender Male
Status Offline
Is there anything suitable for 2000?
Floor 30 Posted 2007-07-03 20:09 ·  中国 江苏 宿迁 电信
初级用户
★★
Batchs上議院參議長
Credits 199
Posts 105
Joined 2007-06-05 12:00
19-year member
UID 90300
Gender Male
From 江苏
Status Offline
I have a USB flash drive.
Top one
『生如夏花之绚烂
死若秋叶之静美』 dos做到了
Forum Jump: