Solved

I want to make a copying program for vbs

Posted on 2016-10-23
1
47 Views
Last Modified: 2016-10-24
I have got this far and I am stuck. I want to make a program which copies itself to another location, but when it discovers its location, it doesn't add its own filename to the variable, How do you add the file name onto the end of the variable?
My code is here:

Option Explicit
Dim wshShell
Dim oFSO
Dim sScriptDir
Dim sTargetFolder
Dim sCmd
set wshShell  = CreateObject("Wscript.Shell")

Set oFSO = CreateObject("Scripting.FileSystemObject")

sScriptDir = oFSO.GetParentFolderName(WScript.ScriptFullName)
msgBox "Location," & sScriptDir
sTargetFolder = "C:\Users\Arion\Documents\Environment\Test"
 
sCmd = "%comspec% /c copy """ & sScriptDir & """ """ & sTargetFolder & """ /Y"

==================================================EDIT:

This doesn't work either, shame, It should do, I can see why though, It recognises \wippre-alpha.vbs on the end as a string.

Option Explicit
Dim wshShell
Dim oFSO
Dim sScriptDir
Dim sTargetFolder
Dim sCmd
Dim sScriptDirfn
set wshShell  = CreateObject("Wscript.Shell")

Set oFSO = CreateObject("Scripting.FileSystemObject")

sScriptDir = oFSO.GetParentFolderName(WScript.ScriptFullName)
sScriptDirfn = sScriptDir & "\wippre-alpha.vbs"
msgBox "Location," & sScriptDirfn
sTargetFolder = "C:\Users\Arion\Documents\Environment\Test"
 
sCmd = "%comspec% /c copy """ & sScriptDirfn & """ """ & sTargetFolder & """ /Y"
0
Comment
Question by:Arion Sejdia
1 Comment
 
LVL 53

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 41856273
This seemed to work for me, and copied the VBS file to the target folder.

Option Explicit

Dim objShell, strCmd, strTargetFolder

strTargetFolder = "B:\ee\EE28978298\dest"

Set objShell = CreateObject("WScript.Shell")

strCmd = "%comspec% /c copy """ & WScript.ScriptFullName & """ """ & strTargetFolder & """ /Y"
objShell.Run strCmd

Open in new window

~bp
1

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question