gpt4 book ai didi

c# - 打开的 exe 文件未完全复制

转载 作者:行者123 更新时间:2023-11-30 23:19:41 26 4
gpt4 key购买 nike

我使用下面的代码行将打开的 exe 复制到另一个文件夹(windows 启动)

File.Copy(ownPath, Path.Combine(startupFolder, "Player.exe"));

但问题是我的 exe 大小是 16 MB,它的复制大小是 12KB。那么,如果它是打开的,我该如何完整复制一个 exe。我 check here on stack它说如果 exe 打开则无法完全复制。因此,当应用程序首次运行时,我必须将 exe 添加到启动文件夹中。

最佳答案

这里的一个答案建议使用 Shadow Copy: How to copy a file while it is being used by other process

但我不确定卷影副本是否始终可用。

您是否正在尝试让程序在 Windows 启动时启动?如果是这样,您可以在不复制的情况下这样做: How to make an exe start at the Windows Startup

或者如果你真的需要制作一个副本,那么你可以确保该程序还没有运行,如果是,请让用户先停止它: Check if a specific exe file is running

编辑:

我在 MSDN 的注册表文档中没有发现工作目录。可能有两种解决方法:1. 如果可执行文件支持,可以将工作目录作为参数传递。2. 您可以尝试使用注册表中的启动器,例如cmd.exe 或 powershell:

cmd.exe /c [Batch file to change directory and launch EXE]

powershell.exe -windowstyle hidden start-process [Path to EXE] -WorkingDirectory [WorkingDir] The -windowstyle hidden only works for Powershell V2. You'll otherwise get a console window briefly.

关于c# - 打开的 exe 文件未完全复制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40145640/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com