无法通过C#来删除.exe文件 [英] Unable to delete .exe file through c#

查看:518
本文介绍了无法通过C#来删除.exe文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有窗内的更新按钮形成application.When上的更新按钮,用户点击时,应用程序检查与从Web服务中获得的服务器中可用的版本的应用程序的当前版本。如果有版本之间的不匹配,应用程序会下载从Web服务中获得的路径新版本。

I have an update button within the windows form application.When the user clicks on the update button, the application checks the current version of the application with the version available in the server obtained from the webservice. If there is mismatch among versions,the application will download the new version from the path obtained from the webservice.

我目前使用相同的解决方案中的两个项目。

I am currently using two projects within the same solution


  1. 其中运行应用程序
  1. Main project where the application is running

更新项目

主要项目 - 其目的是用来删除.exe文件,下载新的.exe文件。 (更新项目被添加为主要项目的参考)

Update project -Its purpose is used to delete the .exe file and download the new .exe file. (Update project is added as a reference of Main project)

现在的问题是,当我尝试删除mainproject。 exe文件通过更新项目的代码,它显示了一个异常说未授权异常捕获。没有人知道为什么会这样?或有没有人有更好的主意使用的应用程序?

The problem is when i try to delete the mainproject.exe through code in update project,it shows an exception saying "Unauthorized exception caught". Does anyone knows why this is happening?OR Does anyone have a better idea to use update function within the application??

这是代码,我使用的删除内更新功能该文件。

This is the code that i am using for the deleting the file.

未经授权异常Windows窗体 - C#

编辑: -

而我在调试应用程序,亚姆能够删除该.exe file.But当我尝试在桌面上安装后删除该应用程序,再次获得荫异常消息为访问被拒绝。

While i was debugging the application,iam able to delete the .exe file.But when i try to delete the application after installing in the desktop,again iam getting the exception message as "Access is denied".

推荐答案

我发现为什么IAM收到访问被拒绝异常在我的应用程序的解决方案。

I found the solution why iam getting the "access is denied" exception in my application.

由于IAM删除应用程序中的文件通过代码我需要有管理员权限。

Since iam deleting a file inside the application through code i need to have the privilege of "Administrator".

的一种方法是使用户登录手动为administrator.But这不是一个更好的选择。

One way is to make the user login manually as administrator.But that is not a better option.

另一种方式是在项目中创建一个应用程序清单文件和设置的级别为administartor。

Another way is to create an App Manifest file within your project and set the level as "administartor."

创建应用程序清单 - >右键点击项目 - >添加新项 - >从右侧pane-选择应用清单选项>单击确定

打开清单文件并更改级别设置为requireAdministartor。

Open the manifest file and change the level to "requireAdministartor".

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />



在运行应用程序这将解决这一问题,它会提示用户以管理员身份运行。

This will solve the issue while running the application,it will prompt user to run as administrator.

希望这将有助于有人在未来。 :)谢谢你们的支持。

Hope this will be helpful to someone in future. :) Thank you guys for your support.

这篇关于无法通过C#来删除.exe文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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