Solved

I want to make a copying program for vbs

Posted on 2016-10-23
1
25 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 51

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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now