使用快捷方式运行可执行文件时复制操作失败

发布于 2024-09-03 03:42:11 字数 377 浏览 2 评论 0原文

我编写了一个使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

却一份温柔 2024-09-10 03:42:11

您的代码依赖于当前工作目录。重新格式化命令,这样就不会出现这种情况。

或者,向我们展示您传递的 [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.

不羁少年 2024-09-10 03:42:11

我发现了问题所在。我使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文