Solved

# I want to make a copying program for vbs

Posted on 2016-10-23
44 Views
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
Question by:Arion Sejdia
1 Comment

LVL 53

Accepted Solution

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

~bp
1

## Featured Post

Question has a verified solution.

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

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …