Solved

Use WshShell.Run to copy a file

Posted on 2007-11-21
4
5,100 Views
Last Modified: 2010-05-18
I'm tring to copy a file to 'All Users\Start Menu\Programs\Startup' folder.  I keep getting an error telling me it can't find the file specified.  The file is definitely in the 'd:\scripts' folder and it is definitely named 'JoinDomain.vbs'.

I'm sure the problem is syntax related, but I can't seem to find the answer.  Please help!

Thanks in advance.
Set oShell = CreateObject("Wscript.Shell")

strAllUser = oShell.ExpandEnvironmentStrings("%ALLUSERSPROFILE%")

DestAllStart = strAllUser & "\Start Menu\Programs\Startup"

ScriptPath = "d:\Scripts"

JDScript = ScriptPath & "\JoinDomain.vbs"

ShellCMD = "copy " & JDScript & " " & CHR(34) & DestAllStart & CHR(34) & " /Y"
 

Const OverwriteExisting = True

'Set objFSO = CreateObject("Scripting.FileSystemObject")

set WshShell = CreateObject("WScript.Shell")

WshShell.Run ShellCMD

Open in new window

0
Comment
Question by:VelocityNet
  • 2
  • 2
4 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 20330764
Hi, try this....

'================
Set oShell = CreateObject("Wscript.Shell")
strAllUser = oShell.ExpandEnvironmentStrings("%ALLUSERSPROFILE%")
DestAllStart = strAllUser & "\Start Menu\Programs\Startup"
ScriptPath = "d:\Scripts"
JDScript = ScriptPath & "\JoinDomain.vbs"
ShellCMD = "cmd /c copy " & JDScript & " " & CHR(34) & DestAllStart & CHR(34) & " /Y"
 
Const OverwriteExisting = True
oShell.Run ShellCMD, 1, False
'================

You didn't need to set a second shell object, although that's not the issue, but I have added cmd /c to the ShellCMD line to force the copy command to run inside a command prompt, where we know it works.

You can also change
oShell.Run ShellCMD, 1, False

to
oShell.Run ShellCMD, 0, False

to hide the command prompt.

Regards,

Rob.
0
 

Author Comment

by:VelocityNet
ID: 20331238
Rob....It worked perfectly!

Thank you for your quick response!
0
 

Author Closing Comment

by:VelocityNet
ID: 31410448
Excellent work!
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 20331373
Great, no problem!

Regards,

Rob.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

705 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