为什么我可以在 XP 上使用 Win32::GuiTest 驱动 InstallShield,但不能在 Windows 7 上驱动?
我正在尝试使用 Win32::GuiTest 来测试基于 InstallShield 的卸载过程。我可以打开控制面板,找到应用程序,然后调用 InstallShield,但我所做的任何事情似乎都不允许我选择安装程序中的“删除”按钮。到目前为止,我已经得到:
sub uninstall($;$) {
my ($name, $force) = @_;
if (! defined($force)) {
$force=0;
}
my @windows;
# Control Panel window
my $cpwin;
my $w;
my $text;
# Install Shield window
my $iswin;
# Run the Control Panel (In windir, do `control appwiz.cpl`)
system("cd %windir% && control appwiz.cpl");
sleep 1;
print("Opened control panel\n");
# Get the Window ID of the control panel
# FIXME - this label is system specifie (W7)
@windows = FindWindowLike(undef, "Programs and Features", "");
$cpwin = $windows[0];
printf("Found CP window ID %x\n", $cpwin);
# Get the Folder View window of the control panel
# Find the list of applications
@windows = FindWindowLike($cpwin, "FolderView");
$w = $windows[0];
# Find program in the list
if (Win32::GuiTest::SelListViewItemText($w, $name) == 0) {
printf("Could not find '$name'.\n");
return -1;
}
# Invoke the installer for by pressing [Return]
Win32::GuiTest::SendKeys("~");
# Wait for the "initializing the wizard" window
@windows = Win32::GuiTest::WaitWindow("InstallShield Wizard", 5);
# Wait for the real installer window
sleep 10;
@windows = Win32::GuiTest::WaitWindow("InstallShield Wizard", 3);
$iswin = $windows[0];
# Win32::GuiTest::WaitWindow("Remove");
printf("Found IS window ID %x\n", $iswin);
# Win32::GuiTest::SetFocus($iswin);
@windows = FindWindowLike($iswin, "&Remove", "Button");
my $remove = $windows[0];
printf("Found remove button %x\n", $remove);
Win32::GuiTest::PushButton($remove);
# Win32::GuiTest::SetFocus($remove);
# Win32::GuiTest::SendKeys("%r");
# Win32::GuiTest::MouseClick("Remove",$iswin);
# Win32::GuiTest::CheckButton($remove);
# Win32::GuiTest::SendKeys("{DOWN}{DOWN}");
# Win32::GuiTest::MouseClick("Next",$iswin);
# Win32::GuiTest::PushChildButton($iswin, "Cancel");
我尝试过的所有事情(最后注释掉)似乎都没有任何效果。
我在 Windows 7 上使用 ActivePerl 和 Win32::GuiTest(如果有的话)。
(说得客气一点。我的 Perl 可能很糟糕。我有超过 25 年的编程经验,但使用 Perl 的时间还不到一个月。)
I'm trying to use Win32::GuiTest to test an InstallShield-based uninstall process. I can open the Control Panel, find the application, and invoke InstallShield but nothing I do seems to let me pick the Remove button in the installer. So far, I've got:
sub uninstall($;$) {
my ($name, $force) = @_;
if (! defined($force)) {
$force=0;
}
my @windows;
# Control Panel window
my $cpwin;
my $w;
my $text;
# Install Shield window
my $iswin;
# Run the Control Panel (In windir, do `control appwiz.cpl`)
system("cd %windir% && control appwiz.cpl");
sleep 1;
print("Opened control panel\n");
# Get the Window ID of the control panel
# FIXME - this label is system specifie (W7)
@windows = FindWindowLike(undef, "Programs and Features", "");
$cpwin = $windows[0];
printf("Found CP window ID %x\n", $cpwin);
# Get the Folder View window of the control panel
# Find the list of applications
@windows = FindWindowLike($cpwin, "FolderView");
$w = $windows[0];
# Find program in the list
if (Win32::GuiTest::SelListViewItemText($w, $name) == 0) {
printf("Could not find '$name'.\n");
return -1;
}
# Invoke the installer for by pressing [Return]
Win32::GuiTest::SendKeys("~");
# Wait for the "initializing the wizard" window
@windows = Win32::GuiTest::WaitWindow("InstallShield Wizard", 5);
# Wait for the real installer window
sleep 10;
@windows = Win32::GuiTest::WaitWindow("InstallShield Wizard", 3);
$iswin = $windows[0];
# Win32::GuiTest::WaitWindow("Remove");
printf("Found IS window ID %x\n", $iswin);
# Win32::GuiTest::SetFocus($iswin);
@windows = FindWindowLike($iswin, "&Remove", "Button");
my $remove = $windows[0];
printf("Found remove button %x\n", $remove);
Win32::GuiTest::PushButton($remove);
# Win32::GuiTest::SetFocus($remove);
# Win32::GuiTest::SendKeys("%r");
# Win32::GuiTest::MouseClick("Remove",$iswin);
# Win32::GuiTest::CheckButton($remove);
# Win32::GuiTest::SendKeys("{DOWN}{DOWN}");
# Win32::GuiTest::MouseClick("Next",$iswin);
# Win32::GuiTest::PushChildButton($iswin, "Cancel");
None of the things I've tried (commented out, at the end) seem to have any effect.
I'm using ActivePerl and Win32::GuiTest on Windows 7 if any of that matters.
(Be kind. My Perl probably sucks. I have >25 years experience programming but less than a month in Perl.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实上,我正在尝试驱动安装程序,这似乎是一个转移注意力的事情。在 XP 上(甚至在虚拟机中),这工作得很好。我怀疑问题在于安装程序显示对话框,而记事本显示窗口,并且 W7 中的处理方式与 XP 中的处理方式不同。我会回到为什么 W7 不起作用,但 XP 是我现在必须做的,所以这就足够了。
The fact that I'm trying to drive an installer, appears to be a red herring. On XP (even in a VM), this works fine. I suspect that the issue is that the installers present dialog boxes whereas Notepad presents a window and those are somehow handled differently in W7 than XP. I'll come back to why W7 doesn't work but XP is what I have to do right now so that's enough.
Win32::GuiTest::PushButton
方法将按钮 Text 或 ID 作为参数,而不是窗口/控件对象。因此您根本不需要调用 FindwindowLike 方法。但是
Win32::GuiTest::PushButton
仅从前台窗口查找按钮,这可能不适用于所有情况。应使用Win32::GuiTest::PushChildButton
。请尝试以下方法:
The
Win32::GuiTest::PushButton
method takes the button Text or ID as parameter, not a window/control object. So you don't need to invokeFindwindowLike
method at all.But
Win32::GuiTest::PushButton
is looking up buttons from the foreground window only, which might be not properly for all the cases. TheWin32::GuiTest::PushChildButton
should be used.Please try this way: