Solved

Use WshShell.Run to copy a file

Posted on 2007-11-21
4
5,303 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 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