简体   繁体   English

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

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

在此处输入图片说明 Is there a way to check if an existing process is already running as Administrator/Elevated from a VB .Net WinForm application?有没有办法检查现有进程是否已经从 VB .Net WinForm 应用程序以管理员/提升身份运行? I have a utility which connects to the Main application via API.我有一个通过 API 连接到主应用程序的实用程序。 This was all working fine on Windows 7 but on Windows 10, my utility was unable to connect to the main program via API.这在 Windows 7 上一切正常,但在 Windows 10 上,我的实用程序无法通过 API 连接到主程序。 I tired lots of things but nothing worked.我厌倦了很多事情,但没有任何效果。 Finally I found that if I run the main program As Administrator, the my API utility worked/connected just like that.最后我发现如果我以管理员身份运行主程序,我的 API 实用程序就像那样工作/连接。 I reviewed the documentation for Process class ( https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process?view=netframework-4.7.2 ) but can't find anything obvious to elevated execution property.我查看了 Process 类的文档( https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process?view=netframework-4.7.2 )但找不到任何明显的提升执行财产。 Any advise or code snippet would be appreciated.任何建议或代码片段将不胜感激。

In Windows 10 Task Manager, you can see if the process is running as Elevated or Not.在 Windows 10 任务管理器中,您可以查看进程是否以 Elevated 运行。 I just need something to capture this in the code.我只需要一些东西来在代码中捕获它。

After some testing around I found that after adding app.manifest file with below settings and adding a property IsElevated in the code, I could see if the exe is running as Elevated or not in Task manager.经过一些测试,我发现在添加具有以下设置的 app.manifest 文件并在代码中添加属性 IsElevated 后,我可以查看 exe 是否在任务管理器中以 Elevated 运行。 Hope this can help anyone looking for similar matter.希望这可以帮助任何寻找类似问题的人。

from app.manifest file:来自 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

When using in the code:在代码中使用时:

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.

相关问题 检查Windows应用程序是否正在运行(不是进程) - Check if Windows Application is running (not process) 检测是否以管理员身份运行,是否具有提升的权限? - Detect if running as Administrator with or without elevated privileges? 检查是否有从Windows Service运行的进程 - Check if there's a process running from Windows Service .NET如何检查Windows进程是否正在作为“应用程序”或“背景应用程序”运行 - .NET How to check if a Windows process is running as an “App” or as a “Background application” C#如何通过管理员提升的cmd运行进程(带参数) - C# how to run a process(with arguments) through an administrator elevated cmd 从另一个管理员身份启动应用程序 - Starting an Application as Administrator from another one 检测是否以提升的权限运行? (包括域管理员帐户) - Detect if running with elevated privileges? (domain administrator accounts included) 从Silverlight OOB应用程序如何检查进程是否正在运行 - From Silverlight OOB application how to check if a process is running 在 Windows 10 上运行的 GUI 应用程序中,处理用户事件的延迟会随时间增加 - The latencies to process the user events increase with time in a GUI application running on Windows 10 在启动和进程间通信方面提升运行 - Running Elevated on Startup & Inter Process Communication
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM