为什么我可以在 XP 上使用 Win32::GuiTest 驱动 InstallShield,但不能在 Windows 7 上驱动?

发布于 2024-11-01 03:37:41 字数 2292 浏览 1 评论 0原文

我正在尝试使用 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 技术交流群。

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

发布评论

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

评论(2

披肩女神 2024-11-08 03:37:41

事实上,我正在尝试驱动安装程序,这似乎是一个转移注意力的事情。在 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.

离旧人 2024-11-08 03:37:41

Win32::GuiTest::PushButton 方法将按钮 Text 或 ID 作为参数,而不是窗口/控件对象。因此您根本不需要调用 FindwindowLike 方法。

但是 Win32::GuiTest::PushButton 仅从前台窗口查找按钮,这可能不适用于所有情况。应使用 Win32::GuiTest::PushChildButton

请尝试以下方法:

#@windows = FindWindowLike($iswin, "&Remove", "Button");
#my $remove = $windows[0];
#printf("Found remove button  %x\n", $remove);
sleep 10;
Win32::GuiTest::PushChildButton($iswin, "&Remove", 50);

The Win32::GuiTest::PushButton method takes the button Text or ID as parameter, not a window/control object. So you don't need to invoke FindwindowLike 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. The Win32::GuiTest::PushChildButton should be used.

Please try this way:

#@windows = FindWindowLike($iswin, "&Remove", "Button");
#my $remove = $windows[0];
#printf("Found remove button  %x\n", $remove);
sleep 10;
Win32::GuiTest::PushChildButton($iswin, "&Remove", 50);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文