测试需要管理权限的程序的安装过程 [英] Testing install procedure of a program requiring administrative privileges

查看:29
本文介绍了测试需要管理权限的程序的安装过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写自动化测试,以确保我的程序的安装程序正常工作.

I'm trying to write automated test, to ensure that the installer for my program works okay.

该程序可以为所有用户(需要管理员权限)或当前用户(不需要管理员权限)安装.该程序还可以自动更新自身,这在某些情况下需要管理员权限,而在某些情况下则不需要.

The program can be installed for all users (requires admin privs), or for current user (does not require admin privs). The program can also autoupdate itself, which in some cases requires admin privileges, and in some cases doesn't.

我正在寻找一种方法,我可以在 UAC 对话框中单击是,允许"进行自动化测试,这样我就可以在许多不同的操作系统上为所有不同的场景编写测试,这样我就可以充满信心当我对安装程序进行更改时,我没有破坏任何东西.

I'm looking for a way where I can have an automated test click "Yes, Allow" on the UAC dialogs, so I can write tests for all different scenarios, on many different operating systems, so that I can be confident when I make changes to the installer that I didn't break anything.

显然,安装程序本身无法做到这一点.但是,我控制了整个机器,并且可以轻松地启动某种具有管理权限的守护进程,测试程序可以建立一个套接字连接,以请求它现在请在 UAC 上单击确定".

Obviously, the installer process itself cannot do this. However, I control the complete machine, and could easily start some sort of daemon process with administrative rights, that the testprogram could make a socket connection to, to request it to "please click ok on the UAC now".

推荐答案

我在寻找有关 UAC 的类似问题的同时,实际上想出了如何做到这一点.您可以执行以下操作:

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

  1. 编写一个以 SYSTEM 身份运行的服务.
  2. 打开在登录会话中运行的 winlogon.exe 实例的进程令牌.
  3. 使用该令牌通过 CreateProcessAsUser 在 Winlogon 桌面上启动帮助程序.

此时,您在 Winlogon(安全)桌面上的登录会话中有一个以 SYSTEM 身份运行的帮助程序进程.从这里您可以使用某种 IPC 机制从您的自动化测试程序到帮助程序进行通信.在 helper 进程中你可以通过 EnumDesktopWindows 来找到 UAC 提示.这是我所接受的;我实际上并没有尝试模拟单击是"或否",但我看不出它为什么不起作用的任何原因.另外,我只在 Windows 7 32 位上测试过;我相信 UAC 架构与 Vista 相同,但我没有对其进行测试.

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.

作为后续,我添加了代码以使用 FindWindow() 找到是"按钮,并且我能够成功地向它发送 BM_CLICK 消息;UAC 提示消失,应用程序被允许运行.

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.

这篇关于测试需要管理权限的程序的安装过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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