Jump to content

Copy file with vbs


joebob105

Recommended Posts

I am quite aware that this is a very n00bish question.

How would I go about copying one file from one location to another location in visual basic script?

I am trying to create something like usbdumper...only in vbs. A batch file won't work because it creates a pop-up error message when it checks a

drive that is non-existent. I have checked google and found several scripts...none of which work. I was hoping that someone here might know more about vbs (or googling stuff) than I.

Much appreciated.

Link to comment
Share on other sites

There are ways to script bat scripts to not show pop up windows, as well as error check and then move on past the errors. VBS will work as well, but if it gets an error, you will get a pop up there as well. Both work, and both can be scripted to error check and work around the problem. Keep googling...

Link to comment
Share on other sites

There are ways to script bat scripts to not show pop up windows, as well as error check and then move on past the errors. VBS will work as well, but if it gets an error, you will get a pop up there as well. Both work, and both can be scripted to error check and work around the problem. Keep googling...

I've continued to google with no real results. The only fix I found for the errors was inserting this registry key:

[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionWindows]

"ErrorMode"=dword:00000002

It will disable all error messages. Couldn't find any way else. I tried to use a "if not exist" command to errorcheck, but it still produced popup error messages. Any other methods of disguising error messages?

Thanks very much.

here is a photo of the windows error message:

errorcd2.th.png

Link to comment
Share on other sites

copy filename

that will produce error messages if the drive doesn't exist

Dont pay any attention to his posts. He is just tyring to be a dick if you go and see all his posts you will see what I mean.

Try this

Open notepad and paste the following in it.

Set WshShell = WScript.CreateObject("WScript.Shell") 
Run_it = WshShell.Run("yourBatScript.bat", 0, True)

Then save it as SomeFile.vbs and see what happens. Change yourBatScript.bat to the path of your bat script you want to run. I am not positive it will hide the error, but see what happens.

Link to comment
Share on other sites

copy filename

that will produce error messages if the drive doesn't exist

Dont pay any attention to his posts. He is just tyring to be a dick if you go and see all his posts you will see what I mean.

Try this

Open notepad and paste the following in it.

Set WshShell = WScript.CreateObject("WScript.Shell") 
Run_it = WshShell.Run("yourBatScript.bat", 0, True)

Then save it as SomeFile.vbs and see what happens. Change yourBatScript.bat to the path of your bat script you want to run. I am not positive it will hide the error, but see what happens.

Ah yes...I can see what you mean.

I tried the .vbs trick. It successfully hides the batch file cmd window, but still produces an error message.

Thanks anyway.

Link to comment
Share on other sites

copy filename

that will produce error messages if the drive doesn't exist

Dont pay any attention to his posts. He is just tyring to be a dick if you go and see all his posts you will see what I mean.

Try this

Open notepad and paste the following in it.

Set WshShell = WScript.CreateObject("WScript.Shell") 
Run_it = WshShell.Run("yourBatScript.bat", 0, True)

Then save it as SomeFile.vbs and see what happens. Change yourBatScript.bat to the path of your bat script you want to run. I am not positive it will hide the error, but see what happens.

Ah yes...I can see what you mean.

I tried the .vbs trick. It successfully hides the batch file cmd window, but still produces an error message.

Thanks anyway.

What is the error message? CP it here.

Link to comment
Share on other sites

Post your code, there may be a way to suppress it and move beyond it on error, but we cant see what your tyring to do with it, so not sure what options there are to work around it.

Link to comment
Share on other sites

Here is my code/string of commands:

:begin
copy "a:" "c:files"
copy "b:" "c:files"
copy "d:" "c:files"
copy "e:" "c:files"
copy "f:" "c:files"
copy "g:" "c:files"
copy "h:" "c:files"
copy "i:" "c:files"
copy "j:" "c:files"
copy "k:" "c:files"
copy "l:" "c:files"
copy "m:" "c:files"
copy "n:" "c:files"
copy "o:" "c:files"
copy "p:" "c:files"
copy "q:" "c:files"
copy "r:" "c:files"
copy "s:" "c:files"
copy "t:" "c:files"
copy "u:" "c:files"
copy "v:" "c:files"
copy "w:" "c:files"
copy "x:" "c:files"
copy "y:" "c:files"
copy "z:" "c:files"
goto begin

This is my first attempt at creating a kind of "usb dumper" to use in the hacksaw so that it is not detected by av.

After some experimentation, I found that no errors occur except on drive "g:", "h:",  "i:", and "j:"

Is there a specific reason for this?

Is it possible for a usb drive to show up on one of these four letters or are they reserved for floppies/ and or network drives?

Because if not, I will just leave them out and my problem will be solved.

Link to comment
Share on other sites

Are you trying to make it so when you plug in your usb drive it copies itself to "c:files" ?

g:", "h:",  "i:", and "j: might be things like different card readers for SD cards, Flash cards, XD cards, etc, or anotehr hard drive(but since its your pc your probably testing i ton, you should know if they are HDD's or not).

If the bat executes upon insertion, try this:

md c:files
xcopy .*.* c:files /S /Y

MD makes a new directory, or the folder files on the c drive.

The ./ in xcopy puts you in the current location of the bat script, the /S with xcopy will copy all files/folders for the folder you are currently in and any sub folders and files. /Y says yes to overwrite any existing files, but that is up to you.

Then, to make it run silent, use the VBS script trick to run the bat script.

Link to comment
Share on other sites

Are you trying to make it so when you plug in your usb drive it copies itself to "c:files" ?

g:", "h:",  "i:", and "j: might be things like different card readers for SD cards, Flash cards, XD cards, etc, or anotehr hard drive(but since its your pc your probably testing i ton, you should know if they are HDD's or not).

If the bat executes upon insertion, try this:

md c:files
xcopy .*.* c:files /S /Y

MD makes a new directory, or the folder files on the c drive.

The ./ in xcopy puts you in the current location of the bat script, the /S with xcopy will copy all files/folders for the folder you are currently in and any sub folders and files. /Y says yes to overwrite any existing files, but that is up to you.

Then, to make it run silent, use the VBS script trick to run the bat script.

Sorry I wasn't clearer. I am trying to create a program which remains resident on a computer.

When *any* usb drive is plugged in, the contents of it are dumped onto the HD so that they can be emailed off.

This is precisely what the hacksaw does? So why am I trying to do this if hacksaw already exists?

USB Dumper is detected by most antivirus programs.

The script needs to be able to scan all drives (except c:) for information while not delivering error popups for nonexistent drives.

Are the error popups merely something that occurs on my computer? Or is it universal as well?

Thanks again.

Link to comment
Share on other sites

One thing is your bat script is just going to go into an infinite loop try to copy files it already copied. Continuously copying files will also make it prompt you to overwrite the files if they already exists, which will throw a kink in your bat script once it gets done and start over. Your probably not getting this far, since it seems you get an error trying to copy from a drive or media that isnt mounted. If your tyring to copy from removable media, or drive letters assigned to removable drives that have nothing mounted in them, like a floppy, media reader for SD/XD/Compact Flash cards, etc. it will obviously try to throw an error or prompt of some sort.

One thign you can do is try to trap the error code and then put somthing in the vbs script that says on error #such and such resume next or something like that, but even that probably isnt the cleanest way to do it.

You would probably need to query the system somehow to see what drives are mounted and writable/readable, then copy from the found drive letter(s) that have the files you want to copy from. This would be the best solution.

I havent used any of these USB hacks, so if I were you, I would go back and look at the original code used in those and modify to your needs.

Link to comment
Share on other sites

I'm about to go to work but when I get home I will post some links explaining what you will need to do, and throw together a few examples to help explain.

After a little more googling, I found a program which is capable of removing unnecessary drive letters while it is running.

My script works with no error popups now.

@Gonzor

Please feel free to post the links anyway seeing as there might be a better way

(thinking outloud...a way where admin is not required- the program I am using does).

Thanks everyone for the help!

Link to comment
Share on other sites

I'm about to go to work but when I get home I will post some links explaining what you will need to do, and throw together a few examples to help explain.

After a little more googling, I found a program which is capable of removing unnecessary drive letters while it is running.

My script works with no error popups now.

@Gonzor

Please feel free to post the links anyway seeing as there might be a better way

(thinking outloud...a way where admin is not required- the program I am using does).

Thanks everyone for the help!

Sorry about the delay in posting, I thought I would have some free time after work the other day but it turns out I have had to work double shifts this week, I will post an example when I get time, it should overcome the admin problem.

Link to comment
Share on other sites

I'm about to go to work but when I get home I will post some links explaining what you will need to do, and throw together a few examples to help explain.

After a little more googling, I found a program which is capable of removing unnecessary drive letters while it is running.

My script works with no error popups now.

@Gonzor

Please feel free to post the links anyway seeing as there might be a better way

(thinking outloud...a way where admin is not required- the program I am using does).

Thanks everyone for the help!

Sorry about the delay in posting, I thought I would have some free time after work the other day but it turns out I have had to work double shifts this week, I will post an example when I get time, it should overcome the admin problem.

Great! Can't wait to see the example.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...