Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to copy and paste a file on to a VBScript file.

Status
Not open for further replies.

stevemarks59

Technical User
Apr 8, 2010
22
US
Does anyone know how to write a script that would specifically
copy a file "File.ext" to the clipboard and paste it to this
"My Script.vbs" file?

I do not mean editing the VBScript file. I currently right click
"File.ext" select "Copy" then right click "My Script.vbs" and
select "Paste".

I would like to know if I can do that with a script. I have
included an example of the code used in "My Script.vbs" I have
chosen these file names and directory paths to use as examples
for my post.

I thank you for reading this.

My Script.vbs

Code:
On Error Resume Next
Const OverwriteExisting = True
Set objArgs = WScript.Arguments
Set objFSO = CreateObject("Scripting.FileSystemObject")

If objArgs.Count < 1 Then
    WScript.Quit
End If

For I = 0 to objArgs.Count - 1
   Arg = objArgs(I)

   objFSO.CopyFile Arg, "C:\Desktop\", OverwriteExisting
   objFSO.CopyFile Arg, "D:\Desktop\", OverwriteExisting
   objFSO.CopyFile Arg, "E:\Desktop\", OverwriteExisting
   objFSO.CopyFile Arg, "F:\Desktop\", OverwriteExisting
   objFSO.CopyFile Arg, "G:\Desktop\", OverwriteExisting

   objFSO.CopyFolder Arg, "C:\Desktop\", OverwriteExisting
   objFSO.CopyFolder Arg, "D:\Desktop\", OverwriteExisting
   objFSO.CopyFolder Arg, "E:\Desktop\", OverwriteExisting
   objFSO.CopyFolder Arg, "F:\Desktop\", OverwriteExisting
   objFSO.CopyFolder Arg, "G:\Desktop\", OverwriteExisting

Next
WScript.Quit
 
This is what worked for me:
I converted the vbs file to an exe file using ScriptCryptor.
I use a script to open the file I want copied using that exe file.
 
You can drag and drop (or copy and paste) a group of files onto your existing script or if you run it from a command line, pass the files as arguments:
Code:
path to script\myscript.vbs file1.ext file2.ext file3.ext ...
If you have a group of files that you commonly use this script for, you can write a 2nd script that will call your script as above with the file names.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top