tags:

views:

51

answers:

2

I've coded a C# executable that uses xcopy (cmd.exe /Q /D /C xcopy "C:\_Depot\Tools\CAD\2009" "C:\Apps\CAD 2009" /E /K /R /Y) to duplicate some files.

If I run the .exe by double-clicking it, the xcopy operation works every time.

If I run the .exe by double-clicking a shortcut to the .exe, the xcopy works only if the shortcut is in the same folder as the .exe.

I've tried setting the current directory to the executing assembly's folder, but that's no help.

The "Start in:" value of the shortcut has been the same folder as the .exe in all of my test. (Not that this should matter -- I want the code to work regardless of the value.)

Any ideas, people?

+2  A: 

Your code relies on current working directory. Reformat the command so that it wouldn't.

Or, show us the [args] you pass, we'll try to help.

Pavel Radzivilovsky
I like that reputation score. (`3333`)
SLaks
"I like that reputation score." ... I just got here, dude. WTF.
MiloDC
"... show us the [args] you pass, we'll try to help." -- Will do, I'll edit my question to include that information.
MiloDC
Guys, either you remove irrelevant comments or I delete my answer. We should not pollute the information space. Think about future google searches who are busy working on a deadline, instead being fed with the irrelevant argument.
Pavel Radzivilovsky
A: 

I figured out the problem. Instead of Windows Explorer, I use xplorer2, which I run as administrator. When I opened the shortcut from xplorer2, the copy operation worked. When I opened it from the desktop, however, the copy failed. I tested this by opening the shortcut first from the actual desktop (failure), then from C:\Users[username]\Desktop\ in xplorer2 (success). My code copies files to the Program Files branch, which Windows does not permit without administrative access, of course. Sorry for the confusion.

MiloDC