[英]Access is denied when deleting/downloading a new .exe in VB.net
I know there are a lot of similar questions, but they seem to be about AppData. 我知道有很多类似的问题,但它们似乎与AppData有关。 However, my path is 'C:\\Program Files (x86)\\Project\\My Product Name\\Database\\Project.exe'.
但是,我的路径是“ C:\\ Program Files(x86)\\ Project \\ My Product Name \\ Database \\ Project.exe”。 I get an error message when trying to delete this saying
System.UnauthorizedAccessException: Access to the path 'C:\\Program Files (x86)\\Project\\My Product Name\\Database\\Project.exe' is denied.
尝试删除这句话时,我收到错误消息
System.UnauthorizedAccessException: Access to the path 'C:\\Program Files (x86)\\Project\\My Product Name\\Database\\Project.exe' is denied.
Is this because you have to have Admin Privileges for changing things in Program Files? 这是因为您必须具有“管理员权限”才能更改程序文件中的内容吗? If so, could I create it so it installs it into Libraries/Documents or something?
如果是这样,我可以创建它以便将其安装到库/文档中吗? Extra info if needed -
如果需要的其他信息-
I am using Install Shield and Visual Studio 2013. 我正在使用Install Shield和Visual Studio 2013。
Update----------------------------------------------------- 更新------------------------------------------------- ----
The way I am trying to delete it/replace the file is: 我尝试删除/替换文件的方式是:
I have "Main Form" and "Updater Form". 我有“主表格”和“更新程序表格”。 And what happens is, MainForm opens UpdaterForm and then closes itself.
发生的是,MainForm打开UpdaterForm,然后自行关闭。 Like so...
像这样
Private Sub UpdateBtn_Click(sender As Object, e As EventArgs) Handles UpdateBtn.Click
Updater.Show()
Me.Close()
End Sub
Then in the UpdaterForm this happens... 然后在UpdaterForm中发生这种情况...
Private Sub UpdateBtn_Click(sender As Object, e As EventArgs) Handles UpdateBtn.Click
Main_Menu.Close()
Dim Web As New WebClient
My.Computer.FileSystem.DeleteFile(Application.StartupPath & "/Project.exe")
My.Computer.Network.DownloadFile("MYLINK", Application.StartupPath & "/Project.exe")
End Sub
However on My.Computer.FileSystem.DeleteFile(Application.StartupPath & "/Project.exe")
it says I do not have the permission to edit the file path. 但是,在
My.Computer.FileSystem.DeleteFile(Application.StartupPath & "/Project.exe")
它说我没有编辑文件路径的权限。 I think it is is just the case of moving it somewhere else or making it so UpdaterForm has permissions. 我认为这只是将其移动到其他地方或使其具有UpdaterForm权限的情况。
Also, what I was wondering is would it be better for the UpdaterForm to be a different .exe? 另外,我想知道的是,将UpdaterForm更改为其他.exe会更好吗? Or could I just keep it the same?
还是我可以保持不变?
If you know a lot about Install Shield, could I just use an Upgrade Path, and select to old .msi file? 如果您对Install Shield了解很多,我可以只使用“升级路径”,然后选择到旧的.msi文件吗? But I am not to sure about how it goes about updating etc. If you know more about it could you please explain?
但是我不确定它如何进行更新等。如果您对此有更多了解,可以解释一下吗?
As I mentioned in my comment: I expect this is a UAC issue. 正如我在评论中提到的:我希望这是一个UAC问题。
The method I know of to gain higher privileges is to request a higher execution level in your application manifest file (app.manifest -> Click Show All Files for your project -> expand My Project). 我知道获得更高特权的方法是在应用程序清单文件中请求更高的执行级别(app.manifest->单击“显示项目的所有文件”->展开“我的项目”)。 In there you will find a section that looks like this:
在其中,您将找到一个类似于以下内容的部分:
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC Manifest Options
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
Specifying requestedExecutionLevel node will disable file and registry virtualization.
If you want to utilize File and Registry Virtualization for backward
compatibility then delete the requestedExecutionLevel node.
-->
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
<applicationRequestMinimum>
<PermissionSet Unrestricted="true" ID="Custom" SameSite="site" />
<defaultAssemblyRequest permissionSetReference="Custom" />
</applicationRequestMinimum>
</security>
You want to change your requestedExecutionLevel
to requireAdministrator
or highestAvailable
. 您想要将您的
requestedExecutionLevel
更改为requireAdministrator
或highestAvailable
。
This article at Code Project seems to have a fairly nice walkthrough. Code Project上的这篇文章似乎有相当不错的演练。 Somebody has asked about elevating a process that is already running on Stack Overflow .
有人要求提升已经在Stack Overflow上运行的进程。 It isn't possible, but there is good information here and some useful links.
这是不可能的,但是这里有很好的信息以及一些有用的链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.