帮助以管理员权限打开winforms应用程序 [英] help having a winforms application open with admin rights

查看:55
本文介绍了帮助以管理员权限打开winforms应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须创建一个必须以管理员身份运行的应用程序.现在我知道我可以让用户右键单击并以管理员身份运行,但是如果他们以常规用户帐户打开它,则我需要安全.

与工作有关的是要使用clickonce函数,我知道它具有支持管理员权限的功能.

如果它找不到管理员帐户,提示您用uac输入您的管理员凭据,那么在窗体加载时有什么内容吗?请帮助我一直在网上搜索并且没有很多关于此问题的信息.

i m having to create an applicaation that has to run as admin. now i know i can have the user right click and run as admin but i need a safety if they open it as their regular user account.

the catch with this is work wants to use the clickonce function which i know that it dosent support admin rights.

is there any what that on form load if it dosent find an admin account it prompts you with uac to enter in your admin credentials? please help i have been searching the web and not a lot of information out there on this issue.

推荐答案

是的,您可以通过为应用程序添加清单文件来执行此操作并在编译时将其嵌入到您的应用程序中.您可以执行以下步骤来执行此操作.

1.在存在项目文件的同一文件夹中创建一个名称为<<<应用程序名称>> .exe.manifest"的文件.
2.在下面提供的行中写上
Yes you can perform this by adding a manifest file for your application and embed it to your application while compilation. You can perform following steps for doing this.

1. Create a file having name "<<application name>>.exe.manifest" in the same folder where project file is present.
2. Write below provided lines in it
<?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.0.0.0" name="ApplicationName"/>
  <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>



3.确保在上面的XML中提供您的可执行文件名称,以代替应用程序名称.

4.现在转到项目属性->配置属性->链接器->清单文件".
5.将"UAC执行级别"更改为"requireAdministrator".
6.之后,转到项目属性->配置属性->清单工具->输入和输出".
7.在其他清单文件"文本框中添加清单名称.
8.现在编译应用程序并生成可执行文件.
9现在,当您运行此应用程序时,它将需要管理员权限.

请在链接 [



3. Make sure that in place of Application name, provide your executable name in above XML.

4. Now go to "Project Properties->Configuration Property->Linker->Manifest File".
5. Change "UAC Execution Level" to "requireAdministrator".
6. After this go to "Project Properties->Configuration Property->Manifest Tool->Input and Output".
7. Add yo9ur manifest name in "Additional Manifest Files" text box.
8. Now compile the application and generate executable.
9 Now when you will run this application, it will require admin privileges.

Please find more details for creating and embedding a manifest file at link[^]


我做什么打开应用程序时,将创建我自己的更新程序.然后,我使用Visual Studio创建了一个安装程序,当安装新更新时,它将删除旧版本并安装新版本.这样就可以拥有完整的管理员权限.
What I have done is created my own updater when the application opens. Then I created an installer with visual studio that when a new update installs It will remove the old version and install the new one. This makes it so I can have full admin rights.


这篇关于帮助以管理员权限打开winforms应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆