[英]Overwrite restricted application file?
I'm trying to manually patch my application. 我正在尝试手动修补我的应用程序。 The application makes use of a Service which i make sure to stop and uninstall prior to attempting any overwriting of the application dll's.
该应用程序利用服务,在尝试覆盖该应用程序dll之前,我确保已停止并卸载该服务。
The issue is that i can't overwrite, or even delete some of the dll files which are the core of the application, these dll files are used by the service i uninstalled first. 问题是我无法覆盖甚至删除某些dll文件,而这些dll文件是应用程序的核心,这些dll文件由我首先卸载的服务使用。
I use the following method to pass in the new file-path in order to replace the old DLL which is located inside the root directory of the application in C:\\Program Files\\AppName\\
我使用以下方法传递新的文件路径,以替换位于
C:\\Program Files\\AppName\\
应用程序根目录内的旧DLL C:\\Program Files\\AppName\\
public static bool CopyFile(string newFile, string oldFile) {
公共静态布尔CopyFile(string newFile,string oldFile){
var newfile = new FileInfo(newFile); var oldfile = new FileInfo(oldFile); var f2 = new FileIOPermission(FileIOPermissionAccess.AllAccess, oldFile); f2.AddPathList(FileIOPermissionAccess.Write | FileIOPermissionAccess.Read, newFile); try { f2.Demand(); } catch (SecurityException s) { Console.WriteLine(s.Message); } for (int x = 0; x < 100; x++) { try { File.Delete(oldfile.FullName); newfile.CopyTo(oldfile.FullName, true); return true; } catch { Thread.Sleep(200); } } return false; }
I just wish to provide a new file and remove the old one, replace it, overwrite it.... The application 我只希望提供一个新文件并删除旧文件,替换它,然后覆盖它。
Note: The application i run to do the patching runs as administrator. 注意:我运行的用于修补的应用程序以管理员身份运行。
Any idea? 任何想法?
I was able to fix this issue by making use of a "middle man" in other words, another application which downloads another executable and passes command line arguments to it. 我能够通过使用“中间人”来解决此问题,换句话说,是另一个应用程序,该应用程序下载另一个可执行文件并将命令行参数传递给它。
Originally, my service would download an executable (call it Installer.exe
). 最初,我的服务将下载一个可执行文件(称为
Installer.exe
)。 Installer.exe
would then attempt to stop the service and patch the content, this did not work. 然后,
Installer.exe
将尝试停止该服务并修补内容,但这不起作用。
I now have the service running, it downloads " Installer.exe
". 我现在正在运行该服务,它将下载“
Installer.exe
”。
Installer.exe
will load up and download PatchPayload.exe
. Installer.exe
将加载并下载PatchPayload.exe
。
PatchPayload.exe
runs and kills off the Service, uninstalls it and then download all required patch content from a centralized server and patch the service core files individually then install the service and run it again. PatchPayload.exe
将运行并PatchPayload.exe
该服务,将其卸载,然后从集中式服务器下载所有必需的修补程序内容,并分别对服务核心文件进行修补,然后安装该服务并再次运行它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.