Solved

Use WshShell.Run to copy a file

Posted on 2007-11-21
4
5,420 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

623 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