Question

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?

Was it helpful?

Solution 2

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top