运行需要服务管理员帐户的应用程序

发布于 2024-10-09 12:51:28 字数 342 浏览 6 评论 0原文

是否可以从服务(在Windows7中)运行handle.exe(来自sysinternals)而不必关闭UAC?

该服务是一个自定义的 c-app,需要找出哪个进程正在锁定它尝试访问的文件,handle.exe 似乎是解决它的好方法,但我无法让它在打开 UAC 的情况下工作。这个应用程序一直运行,所以我在运行时无法看到 UAC 提示,但如果它在启动时出现就可以了。

Handle.exe 在管理命令提示符下工作正常,但在尝试从正常提示符下运行时失败。

我从 CreateProcess() 调用handle.exe 并从管道获取输出。我想应该有办法解决这个问题,但我无法弄清楚。设置服务以从管理员帐户登录似乎不起作用。

Is it possible to run handle.exe (from sysinternals) from a service (in windows7) without having to turn off UAC?

The service is a custom c-app that needs to find out which process is locking a file it tries to access and handle.exe seems to be a good way to solve it but i can't get it to work with UAC turned on. This app runs all the time so i can't have a UAC prompt while its running but its fine if it shows up at startup.

Handle.exe works fine from an admin commandprompt but fails when trying to run from a normal prompt.

I call handle.exe from CreateProcess() and get the output from pipes. I guess there should be a way to solve this but i can't figure it out. Setting up the service to log in from an admin account does not seem to work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一紙繁鸢 2024-10-16 12:51:28

UAC 不会影响服务(它只影响交互式会话),因此应该可以工作。

但是,如果您不想将整个程序转移到服务中,那么有更好的方法可以做到这一点,除了主程序之外,不需要创建、安装和管理单独的服务进程。

  1. 如果您的程序需要管理员权限才能工作,并且这不是唯一需要管理员权限的地方,那么您可以将您的程序(通过其嵌入的清单资源)标记为需要管理员权限。然后,每当运行时它都会触发一个 UAC 提示,并以完全管理员权限运行,包括运行 Handle.exe 的能力。

  2. 另一方面,如果这是您的程序唯一需要管理员权限的地方,那么创建一个 COM DLL 来包装您的 Handle.exe 调用(或任何其他管理工作)可能是有意义的,以便您可以使用 UAC从非提升的应用程序对该函数进行提升的调用。然后,每次创建该 COM 对象(的提升版本)时都会触发 UAC 提示。您可以根据需要将 COM 对象保持打开状态,并在需要时创建它,因此 UAC 提示出现的时间和频率仍然取决于您。

1 和 2 2 是 UAC 的标准用法,因此任何有关 UAC 的优秀文档或教程都会详细描述如何执行它们。

UAC does not affect services (it only affects interactive sessions) so that should work.

However, if you don't want to move your entire program into a service then there are better ways to do this which don't require creating, installing and managing a separate service process in addition to your main program.

  1. If your program requires admin rights to work at all, and this isn't the only place it will require them, then you could flag your program (via its embedded manifest resource) as requiring administrator rights. It will then trigger one UAC prompt whenever it is run and be run with full admin rights, including the ability to run Handle.exe.

  2. On the other hand, if this is the only place where your program needs admin rights, it may make sense to create a COM DLL which wraps your Handle.exe call (or any other admin work) so that you can use UAC to make elevated calls to that function from your non-elevated app. You will then trigger a UAC prompt each time you create (an elevated version of) that COM object. You can keep the COM object open as long as you want, and create it whenever you want, so when and how often the UAC prompt(s) appear are still up to you.

Both 1 & 2 are standard uses of UAC so any good documentation or tutorial on UAC will describe how to do them in detail.

凤舞天涯 2024-10-16 12:51:28

您可能想查看 Win32 API 方法 CreateProcessWithLogonW。
这里还有一个 elevate VBS 脚本,您可以从中学习:http:// technet.microsoft.com/en-us/magazine/2007.06.utilityspotlight.aspx

You may want to look at the Win32 API method CreateProcessWithLogonW.
There is also an elevate VBS script here you may learn from: http://technet.microsoft.com/en-us/magazine/2007.06.utilityspotlight.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文