使用快捷方式运行可执行文件时复制操作失败
我编写了一个使用 xcopy 的 C# 可执行文件 (cmd.exe /Q /D /C xcopy "C:\_Depot\Tools\CAD\2009" "C:\Apps\CAD 2009" /E /K /R /Y )复制一些文件。
如果我通过双击运行 .exe,则 xcopy 操作每次都会起作用。
如果我通过双击 .exe 的快捷方式来运行 .exe,则仅当该快捷方式与 .exe 位于同一文件夹中时,xcopy 才起作用。
我尝试将当前目录设置为执行程序集的文件夹,但这没有帮助。
在我的所有测试中,快捷方式的“开始于:”值与 .exe 位于同一文件夹。 (这并不是说这很重要——我希望代码能够工作,无论其值如何。)
大家有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的代码依赖于当前工作目录。重新格式化命令,这样就不会出现这种情况。
或者,向我们展示您传递的 [args],我们会尽力提供帮助。
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.
我发现了问题所在。我使用 xplorer2,而不是 Windows 资源管理器,我以管理员身份运行它。当我从 xplorer2 打开快捷方式时,复制操作起作用了。然而,当我从桌面打开它时,复制失败。我通过首先从实际桌面打开快捷方式(失败),然后从 xplorer2 中的 C:\Users[用户名]\Desktop\ 打开快捷方式(成功)来测试这一点。我的代码将文件复制到 Program Files 分支,当然,如果没有管理访问权限,Windows 不允许这样做。抱歉造成混乱。
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.