简体   繁体   English

在没有UAC的系统上执行具有管理员权限的应用程序

[英]Execute an application with admin rights on system without UAC

I have an application that must be executed with admin rights. 我有一个必须使用管理员权限执行的应用程序。 There is everything fine, if UAC is on. 如果UAC开启,一切都很好。 But, if UAC is turned off, there is no prompt on start (even for standard user) and application starts with restricted rights. 但是,如果关闭UAC,则启动时没有提示(即使对于标准用户),应用程序也会以受限制的权限启动。

Start process with verb "runas" does not work. 动词“runas”的启动过程不起作用。

Is there any way to show the standard UAC login dialog for and execute an application with admin rights even if UAC if turned off? 有没有办法显示标准的UAC登录对话框,并执行具有管理员权限的应用程序,即使关闭了UAC也是如此?

Update : Manifest is included: 更新 :清单包括:

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <assemblyIdentity version="1.1.6.0" processorArchitecture="X86" name="setup" type="win32"/>
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
        <security>
            <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
                <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
            </requestedPrivileges>
        </security>
    </trustInfo>
</asmv1:assembly>

and everithing is OK, when UAC is active. 当UAC处于活动状态时,即可。 But it does not work if UAC is OFF. 但是如果UAC关闭则不起作用。

Update 2: : This behavior is documented by MSDN Step 6: Create and Embed an Application Manifest (UAC) (see table "Application launch behavior for a standard user account" last row). 更新2 :: MSDN记录此行为步骤6:创建和嵌入应用程序清单(UAC) (请参阅表“标准用户帐户的应用程序启动行为”最后一行)。 So i can't solve this problem with any manifest. 所以我无法用任何清单来解决这个问题。 Is there any other solution? 还有其他解决方案吗?

I had a very similar problem, and I don't think the comments so far addressed your actual issue. 我有一个非常类似的问题,我认为迄今为止的评论并未解决您的实际问题。 I believe they are mistaking the intent of your question. 我相信他们误解了你的问题的意图。 While my answer will not show the actual UAC dialog as you first asked, it will show a workaround. 虽然我的回答不会显示您第一次询问的实际UAC对话框,但它会显示一个解决方法。

UAC being off does NOT preclude an application from being run as Administrator (assuming you have an administrator password, as it seems you do), just makes it harder. UAC被关闭被以管理员身份运行排除应用程序(假设你有一个管理员密码,因为它似乎你这样做),只是使得它更难。 As you rightfully pointed out, with UAC disabled and requireAdministrator set in the manifest, right-clicking and selecting Run as administrator does not actually elevate the process, as Microsoft indicates: "Application might launch but will fail later" 正如您正确指出的那样,在清单中禁用UAC和requireAdministrator ,右键单击并选择Run as administrator并不会实际提升进程,因为Microsoft指示: “应用程序可能会启动但稍后会失败”

Two Steps: 两个步骤:

1) Hold Shift while Right-clicking on the application and select Run as a different user . 1)在右键单击应用程序的同时按住Shift ,然后选择Run as a different user Then simply use your Administrator user name and password to authenticate, and your application should run as Administrator. 然后只需使用管理员用户名和密码进行身份验证,您的应用程序应以管理员身份运行。 It worked for me. 它对我有用。

截图

2) Build a small executable that runs asInvoker and checks for Administrative privileges. 2)构建一个运行asInvoker的小型可执行文件,并检查管理权限。 When it is run without them, warn the user and tell them to Shift-Right Click, then Run as a different user . 在没有它们的情况下运行时,警告用户并告诉他们Shift-Right Click,然后Run as a different user If your small program has administrator access, then use ShellExecute to invoke your primary requireAdministrator application. 如果您的小程序具有管理员访问权限,则使用ShellExecute调用主要的requireAdministrator应用程序。 See Figure 9 here for a flow diagram. 有关流程图,请参见此处的图9

Here is a small code sample in C++ from somewhere on StackOverflow that checks for administrator access: 以下是来自StackOverflow某处的C ++中的一个小代码示例,用于检查管理员访问权限:

BOOL IsUserAdmin(VOID)
{
   BOOL b;
   SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
   PSID AdministratorsGroup; 
   b = AllocateAndInitializeSid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &AdministratorsGroup); 
   if(true==b) 
   {
      if (!CheckTokenMembership( NULL, AdministratorsGroup, &b)) 
      {
         b = FALSE;
      } 
      FreeSid(AdministratorsGroup); 
   }
   return(b);
}

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

相关问题 如何创建一个 windows 应用程序,该应用程序应该在.Net C# 中以管理员权限运行,而不会一次又一次地提示 UAC? - How can I create a windows application that should run with admin rights in .Net C# without prompting UAC again and again? 没有UAC / admin权限的主机WCF应用程序 - Host WCF application without UAC/admin privilege 安装没有管理员权限的 WinForms 应用程序 - Install WinForms application without admin rights 在 Visual Studio 中调试没有管理员权限的应用程序 - Debug application without admin rights in Visual Studio 以管理员权限执行安装程序 - Execute Setup with admin rights 在没有管理员权限的情况下自动更新Vista中的.NET应用程序 - automatically update my .NET application in Vista without admin rights 从没有管理员权限的用户应用程序访问全局互斥锁/信号灯 - acces global mutex/semaphore from user application without admin rights 即使设置了管理员权限,使用msiexec卸载也会出现UAC错误 - Uninstalling with msiexec gets UAC error, even though I have admin rights set 如何在没有管理员权限的情况下安装我的C#应用​​程序? - How Do I Make My C# Application Install Without Admin Rights? .NET应用程序无需网络即可从网络运行 - .NET application to run from network without UAC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM