Solved

Use WshShell.Run to copy a file

Posted on 2007-11-21
4
5,334 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

751 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