I try to execute a single DLL in admin context to force the user to enter UAC when calling a method in case that he is authenticated as a normal user.
I have found the suggestion here: Visual Basic Program - Ask for Admin Permissions
I have tried to create what Nathan M has suggested but I don't get the UAC control displayed.
This is the code I'm using:
Main application:
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
I have added a simple DLL file to the project just for getting the authentication dialog:
Namespace UninstallToken
Public Class GetToken
Public Sub Test()
MsgBox("Test")
End Sub
End Class
End Namespace
And I have created a manifest file which should apply to the DLL with this configuration
<?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>
The project looks like this:
So when I run the program and click the button the DLL is invoked and the MsgBox is displayed but there is no UAC - I'm not running VS as Admin.
Any Ideas what I'm missing? It seems as if the manifest file might be ignored...
I'm using Microsoft Visual Studio Community 2019 Version 16.5.4 on Win 10 19H2 - I execute as normal user.