Testing install procedure of a program requiring administrative privileges

荒凉一梦 提交于 2019-12-03 17:22:10

I actually figured out how to do this while looking to answer a similar question about UAC. Here is what you can do:

  1. Write a service that runs as SYSTEM.
  2. Open the process token of the winlogon.exe instance running in your logon session.
  3. Use that token to launch a helper process on the Winlogon desktop via CreateProcessAsUser.

At this point, you have a helper process running as SYSTEM in your logon session on the Winlogon (secure) desktop. From here you can use some kind of IPC mechanism to communicate from your automated test program to the helper process. In the helper process you can EnumDesktopWindows to find the UAC prompt. This is as far as I took it; I didn't actually try to simulate clicking Yes or No, but I don't see any reason why it wouldn't work. Also, I only tested on Windows 7 32-bit; I believe the UAC architecture is identical to Vista, but I didn't test on it.

It took me a while to figure all this out; I can provide some code if you want.

EDIT: Just as a follow up I added code to use FindWindow() to find the "Yes" button and I was able to successfully send it a BM_CLICK message; the UAC prompt went away and the application was allowed to run.

An alternative solution might be to turn UAC off

The least bad solution I've found so far is to run the tests in a VMWare session, and control the mouse/keyboard trough the vmware sdk. Would love to hear about other solutions

Remote Desktop to it or run it as a guest VM (using Virtual PC or whatever, just don't boot to it.) This is also the best way to take a screenshot or video of the UAC prompt.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!