【发布时间】:2021-08-10 14:16:39
【问题描述】:
我尝试在管理上下文中执行单个 DLL,以强制用户在调用方法时输入 UAC,以防他被验证为普通用户。
我在这里找到了建议:Visual Basic Program - Ask for Admin Permissions
我已尝试创建 Nathan M 建议的内容,但没有显示 UAC 控件。
这是我正在使用的代码:
主要应用:
Imports System
Imports System.Diagnostics.Eventing.Reader
Imports GetUninstallToken.UninstallToken
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
Dim t As New GetToken
t.Test()
Catch ex As Exception
End Try
End Sub
我在项目中添加了一个简单的 DLL 文件,只是为了获取身份验证对话框:
Namespace UninstallToken
Public Class GetToken
Public Sub Test()
MsgBox("Test")
End Sub
End Class
End Namespace
我已经创建了一个清单文件,该文件应该适用于具有此配置的 DLL
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<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 element will disable file and registry virtualization.
Remove this element if your application requires this virtualization for backwards
compatibility.
-->
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
项目如下所示:
因此,当我运行程序并单击按钮时,将调用 DLL 并显示 MsgBox,但没有 UAC - 我没有以管理员身份运行 VS。
任何想法我错过了什么?似乎清单文件可能会被忽略...
我在 Win 10 19H2 上使用 Microsoft Visual Studio Community 2019 版本 16.5.4 - 我以普通用户身份执行。
【问题讨论】:
-
这能回答你的问题吗? Requested Execution Level for a dll
-
嗨@GSerg 感谢您提供的信息。实际上,当我搜索时并没有出现,答案实际上与我之前发现的不同(我认为)......将检查 rundll 的内容,看看是否有帮助。谢谢丹尼尔
-
关于这个问题的第一条评论中链接的答案是正确的:没有“以管理员身份运行 DLL”之类的东西,因为 DLL 包含由进程执行的代码,只有一个进程可以升高。正如另一个答案所说:如果您需要 DLL 中的代码来运行提升,请编写一个调用 DLL 中代码的可执行文件,然后运行提升的可执行文件。