使用process.start运行后删除exe文件的问题 [英] Problem with delete exe file After Run with process.start

查看:142
本文介绍了使用process.start运行后删除exe文件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好吧每个人都用oCodeProvider.CompileAssemblyFromSource编译一个exe文件

然后我运行它:

  Dim  ProcInfo 作为  ProcessStartInfo() 
ProcInfo.FileName =输出
ProcInfo.UseShellExecute = False
ProcInfo.RedirectStandardOutput = True
ProcInfo.CreateNoWindow = True
Dim Proc As Process = Process.Start(ProcInfo)
Proc.WaitForExit()
File.Delete(输出)



但是当我在工作后删除它有错误:

访问被拒绝

我怎么能在下班后删除我的文件?

谢谢。

决方案
没有办法删除当前加载以供执行的可执行模块。你可以删除这样的文件只有在使用它杀死进程(所有这些进程)或等到所有这些进程都自己终止。



如果这是你的子进程通过 System.Diagnostics.Process.Start 创建,这真的很容易。请注意,那些 Start 方法返回对新创建的 System.Diagnostics.Process 实例的引用。您应保留此引用并将其用于 Process.Kill Process.WaitForExit 调用:

http://msdn.microsoft.com/en-us/library/system。 diagnostics.process.aspx [ ^ ]。



请注意,问题中的所有内容都告诉我您使用的是一种非常有问题的技术。什么,你在运行时创建一个应用程序,运行它,然后删除可执行模块。我几乎可以肯定地称之为滥用。有更强大,合法和可靠的技术。如果你正确解释所有这些活动的最终目标,你可以获得更好的建议。



-SA

Hi every one
i compile a exe with oCodeProvider.CompileAssemblyFromSource
then i run it with :

Dim ProcInfo As New ProcessStartInfo()
               ProcInfo.FileName = Output
               ProcInfo.UseShellExecute = False
               ProcInfo.RedirectStandardOutput = True
               ProcInfo.CreateNoWindow = True
               Dim Proc As Process = Process.Start(ProcInfo)
               Proc.WaitForExit()
               File.Delete(Output)


but when i delete it after work it has error :
Access denied
how can i Delete my file after work?
thank you.

解决方案

There is no way to delete an executable module currently loaded for execution. You can delete such file only if kill the process using it (all such processes) or wait until all such processes are terminated by themselves.

If this is your child process created via System.Diagnostics.Process.Start, this is really easy to do. Note that those Start methods return the reference to the newly created instance of System.Diagnostics.Process. You should keep this reference and used it for Process.Kill or Process.WaitForExit calls:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx[^].

Note that everything in your question tells me that you are using a very questionable technique. What, do you create an application during run time, run it, and then delete the executable module(s). I would call it a big abuse, almost certainly. There are much more robust, legitimate and reliable techniques. Chances are, if you properly explain the ultimate goals of all this activity, you can get much better advice.

—SA


这篇关于使用process.start运行后删除exe文件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆