I have a C# project that references a .NET assembly built from a VB.NET project.
This VB.NET assembly requires administrative rights.
I’ve created a manifest in my C# project with:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
and all seems good: when I run:
bool isAdmin = new WindowsPrincipal(WindowsIdentity.GetCurrent())
.IsInRole(WindowsBuiltInRole.Administrator) ? true : false;
from my C# code, I get isAdmin == True as expected, but when I call a method from the VB.NET DLL with:
My.User.IsInRole(Microsoft.VisualBasic.ApplicationServices.BuiltInRole.Administrator)
I get False instead.
This seems very illogical to me.
Furthermore, if I create a VB.NET project with a reference to this VB.NET assembly and run it with admin rights, all works well.
There’s a Note in the MSDN article for My.User that could be significant:
Don’t hesitate to skip My.User and use the C# approach instead.