繁体   English   中英

检查进程是否以管理员身份运行/从另一个应用程序提升 - Windows 10

[英]Check if a process is running as Administrator/Elevated from another application - Windows 10

在此处输入图片说明 有没有办法检查现有进程是否已经从 VB .Net WinForm 应用程序以管理员/提升身份运行? 我有一个通过 API 连接到主应用程序的实用程序。 这在 Windows 7 上一切正常,但在 Windows 10 上,我的实用程序无法通过 API 连接到主程序。 我厌倦了很多事情,但没有任何效果。 最后我发现如果我以管理员身份运行主程序,我的 API 实用程序就像那样工作/连接。 我查看了 Process 类的文档( https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process?view=netframework-4.7.2 )但找不到任何明显的提升执行财产。 任何建议或代码片段将不胜感激。

在 Windows 10 任务管理器中,您可以查看进程是否以 Elevated 运行。 我只需要一些东西来在代码中捕获它。

经过一些测试,我发现在添加具有以下设置的 app.manifest 文件并在代码中添加属性 IsElevated 后,我可以查看 exe 是否在任务管理器中以 Elevated 运行。 希望这可以帮助任何寻找类似问题的人。

来自 app.manifest 文件:

 <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>
Public ReadOnly Property IsElevated As Boolean
    Get
        Return New WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator)
    End Get
End Property

在代码中使用时:

If IsElevated = True Then
                Me.Text = "TEST Utility - Administrator (Elevated)"
            End If
            If IsElevated = False Then
                Me.Text = "TEST Utility - Normal (Non-Elevated)"
            End If

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM