简体   繁体   English

在启动时以管理员身份运行程序

[英]Running Program as Administrator at Startup

I have a kiosk app and want to run it at startup. 我有一个自助服务终端应用程序,并希望在启动时运行它。 The problem here is that when I put Registry value to open it at startup, it doesn't open program as Administrator and so that program doesn't work probably. 这里的问题是,当我将Registry值设置为在启动时打开它时,它不会以管理员身份打开程序,因此该程序可能无法正常工作。 I'm using Windows 7. Can anyone help me with code to run it as Administrator? 我正在使用Windows 7.任何人都可以帮助我使用代码以管理员身份运行它吗? Some programs (such as anit-viruses and the viruses themselves) work as Administrator at startup WITHOUT ASKING THE USER TO ACCEPT RUNNING AS ADMINISTRATOR, that's exactly I want to do. 某些程序(例如anit-virus和病毒本身)在启动时以管理员身份工作,而不会要求用户接受作为管理员运行,这正是我想要做的。 Any help is very thanked. 非常感谢任何帮助。

To run a application at startup, you can either: 要在启动时运行应用程序,您可以:

  1. Run it as a scheduled task, set the credentials to run as the Administrator account, and set it to run at startup (or login). 将其作为计划任务运行,将凭据设置为以管理员帐户运行,并将其设置为在启动(或登录)时运行。
  2. Create a Windows Service, and set the Logon As account to the Administrator account or the Local System account. 创建Windows服务,并将登录身份帐户设置为管理员帐户或本地系统帐户。

Your example of the antivirus software sounds like #2. 您的防病毒软件示例听起来像#2。

You can set the program so you can only run as administrator. 您可以设置程序,以便只能以管理员身份运行。

In Visual Studio : Visual Studio中

Right click on the Project -> Properties -> Security -> Enable ClickOnce Security Settings

After you clicked it, a file will be created under the Project's properties folder called app.manifest once this is created, you can uncheck the Enable ClickOnce Security Settings option 单击它后,将创建一个名为app.manifest的项目属性文件夹下的文件,您可以取消选中Enable ClickOnce Security Settings选项

Open that file and change this line : 打开该文件并更改此行:

<requestedExecutionLevel level="asInvoker" uiAccess="false" />

to: 至:

 <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />

This will make the program require administrator privileges, and it will guarantee you have access to that folder. 这将使程序需要管理员权限,并且它将保证您有权访问该文件夹。

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

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