授予管理员权限才能在启动时启动不UAC提示的应用程序? [英] Granting administrator privileges to an application launched at startup without UAC prompt?

查看:199
本文介绍了授予管理员权限才能在启动时启动不UAC提示的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景

我写了一个小的C#/。NET 4.0应用程序,从安装程序文件复制到游戏同步的各种设置并在不同的机器在同一游戏的其他副本(认为Chrome的书签同步,但在本场比赛)。同步本身是一个相对简单的事,处理与存储游戏的Program Files文件夹中的文件。

I've written a small C#/.NET 4.0 application that syncs various settings from a game installed in Program Files to and from other copies of the same game on different machines (think Chrome bookmark sync, but for this game). The sync itself is a relatively simple affair, dealing with files stored inside the game's Program Files folder.

在我的机器上,能正常工作,而无需通过提升UAC我的申请。 Windows 7中,使游戏中使用Program Files文件虚拟化和我的应用程序工作正常的。

On my machine, this works fine without having to elevate my application through UAC. Windows 7 makes the game use Program Files virtualisation and my application works fine with that.

不过,在很多测试者的机器,我得到的报告,应用程序要么不能与文件和前来情况下工作,甚至不能看到游戏的文件夹!让用户单击右键,然后以管理员身份运行解决了在各种情况下的问题。

However, on a lot of tester's machines, I'm getting reports that the application either can't work with the files and in come cases can't even see the game's folder! Having the user right-click and "Run as Administrator" solves the problem in every case.

因此​​,我们刚刚设置的应用程序清单,要求管理员权限,对不对?这很好(虽然不是理想的)为当用户手动调用的应用程序或同步过程,因为他们会与应用程序,并准备接受UAC要求交互。

So, we just set the application's manifest to require admin privileges, right? That's fine (although not ideal) for when the user manually invokes the application or the sync process because they'll be interacting with the application and ready to accept a UAC request.

然而,我的申请的特征之一是一个同步自动选项,它允许用户设置和忘记的应用程序。有了这一套,该应用程序将自身成HKCU\Software\Microsoft\Windows\CurrentVersion\Run注册表的启动时运行,并在系统托盘中的同步需要后台的设置坐镇。

However, one of the features of my application is a "Sync Automatically" option, which allows the user to "set and forget" the application. With this set, the application puts itself into the registry at HKCU\Software\Microsoft\Windows\CurrentVersion\Run to be run at startup and sits in the system tray syncing the settings in the background as needed.

显然,我需要更聪明在这里。呈现UAC一旦用户登录提示在其帐户或在随机时间间隔之后不向前的方式。

Obviously, I need to be smarter here. Presenting a UAC prompt as soon as the user logs in to their account or at random intervals afterwards isn't the way forwards.

所以,我的问题!

什么是接近的情况下的最佳方式在这里我需要在启动时运行需要管理员权限的应用程序?有没有一种方法,让用户授权,导致系统自动无提示在启动时运行以正确的权限的应用程序/登录?

What's the best way to approach a situation where I'd need to run an application at startup that needs administrator privileges? Is there a way to have the user authorise an installation that causes the system to automatically run the application with the correct privileges without a prompt at startup/login?

更新只是要清楚,这一定是在代码中实现的。

Update Just to be clear, this must be achievable in code.

推荐答案

您应考虑您的同步功能存在的Windows服务中。
这是在Windows上运行的背景功能的首选方法。

You should consider making your Sync functionality exist within a Windows Service. This is the preferred method for running 'background' functionality on Windows.

该服务可以在用户的​​帐户下运行(假设他们有权限修改的文件),也可以使用它做的另一个帐户。最坏的情况下,可以为系统中运行(虽然,这不是最好的做法)。

The Service can either run under the user's account (assuming they have permissions to modify the files), or you can use another account which does. Worst case, you can run as SYSTEM (although, this isn't best practice).

如果你已经得到了你的后台程序功能的工作,那么这应该是一个简单的过程,以在转换为服务。

If you've already got your background process functionality working, then this should be a simple process to convert over to a Service.

这里有一个示例项目,将设置你在正确的道路上:的 http://www.codeproject.com/KB/dotnet/simplewindowsservice.aspx

There's a sample project here that will set you on the right path: http://www.codeproject.com/KB/dotnet/simplewindowsservice.aspx

这篇关于授予管理员权限才能在启动时启动不UAC提示的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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