Solved

I am getting "CMD.EXE was started with the above path as the current directory...

Posted on 2013-05-24
9
6,743 Views
Last Modified: 2013-05-30
Hi All,

I am trying to implement a script which simply copies from a file from a network location to user's computers. the script is simply like this:

@echo off
copy \\server1\share1\file c:\users\user1\desktop\

but when running it the script runs with the following issue:
 "CMD.EXE was started with the above path as the current directory. UNC paths are not supported. Defaulting to windows directory"

I have windows server 2003.

Please advise,

Thank you
0
Comment
Question by:saarmstrong
[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
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 14

Expert Comment

by:Don Thomson
ID: 39194311
try using the following"

@Echo off
net use z: \\server1\share1
copy z:file c:\users1\desktop
net use z: /delete
0
 

Author Comment

by:saarmstrong
ID: 39194316
thank you,
what if the drive is already in use?
0
 
LVL 3

Expert Comment

by:CITG_Carl
ID: 39194326
Try using robocopy scripts rather than copy in cmd.

script is:

robocopy "SOURCE PATH" "DESTINATION PATH" /copyall /mir

http://en.wikipedia.org/wiki/Robocopy
0
Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

 
LVL 14

Expert Comment

by:Don Thomson
ID: 39194408
Use another drive letter
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 39194481
The copy with UNC paths works fine. The message you get only says that the current working directory for the script is not settable, because you are calling the batch from a UNC path. As long as you do not rely on the current directory, i.e. always use absolute paths instead of relative ones, there is no issue (with exception of that distracting message).
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 39194485
Ok.  This is beause you ran the batch file from a UNC share, i.e. \\server\share\whatever.cmd and is no consequence except that the current directory will be c:\windows\system32 or whatever.

Options are:

1. Use a fully qualified copy command like you are anyway so it should work.
2. You can get the filename and path of the batch file using the %~0 variable, i.e.

set mydir=%~dp0
e.g.

@echo off
cls
set mydir=%~dp0
echo You are running %~nx0 from %~dp0.  Current dir is %cd%
copy "%mydir%\myfile.txt" c:\wherever

Open in new window


3. Having got above dir you can use it as part of a copy to get from the same dir as the batch file, or map a drive.  You can "map" a drive using Pushd and Popd and it will map a temporary drive letter, do the job then remove it, e.g.

@echo off
cls
set mydir=%~dp0
echo You are running %~nx0 from %~dp0.  Current dir is %cd%
PUSHD "%mydir%"
  echo now the current dir is %cd%
  copy myfile.txt c:\wherever
POPD

Open in new window


The echo bits are just for info. so you can see where the paths change etc.

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39194490
And BTW if you are not aware the current user desktop directory should normally be:

"%userprofile%\desktop"  so you an use that as the destination in your copy if wanted.

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39209042
Thanks, hope it helped?

Steve
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 39209433
Why that message is print out, and whether it matters, was mentioned by me first. Steve posted only seconds after me, and that is considered to be "at the same time". The added info was informative, but not relevant for the question, so I cannot see why Steve got all the points.
If Experts post similar contents within a few minutes, it is common to accept all such posts.

Could you please explain why http:#a39194485 is "the answer" here?
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

726 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