Powershell:卸载提示用户输入的软件 [英] Powershell: Uninstall Software that has prompts for user input

查看:49
本文介绍了Powershell:卸载提示用户输入的软件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果提示用户输入,是否有人知道是否可以通过 PowerShell 卸载软件?我有多个脚本可以卸载几乎任何东西,除了我需要卸载的一个软件.我特别想卸载下载 PDFCreator 时安装的 PDFForge 工具栏.

Does anybody know if it is possible to uninstall software through PowerShell if it prompts for user input? I have multiple scripts that can uninstall just about anything, except for the one software that I need it to uninstall. I'm specifically trying to uninstall PDFForge toolbar which is installed when downloading PDFCreator.

我编写的脚本都没有失败,它们只是在运行时挂起,我相信是因为卸载过程要求用户输入才能继续.

None of the scripts that I've written fail, they just hang when run, I believe because the uninstall process is asking for user input to proceed.

推荐答案

PowerShell 不会与提示交互...你不能只是告诉它在可执行文件中单击下一步",因为它不能看看吧.

PowerShell isn't going to interact with the prompts... you can't just tell it to click "Next" in an executable because it can't see it.

不过,您可以将密钥发送给它.您实际上只是在使用 COM 对象.

You can send keys to it though. You're really just using COM objects.

因此,首先,通过设置一个包含数组的变量来获取您的进程 ID,该数组的数据由您的进程名称定义.假设您的进程被称为卸载"并且该进程已经在运行:

So, first, get your process ID by setting a variable that contains an array, the data for which is defined by the name of your process. Let's say your process is called, "Uninstall" and the process is ALREADY RUNNING:

$a = Get-Process | ?{$_.Name -eq "Uninstall"}

启动COM:

$wshell = New-Object -ComObject wscript.shell;

将带有此进程 ID 的卸载程序放在最前面,以便我们可以向它发送按键:

Bring the uninstallation program with this process ID to the front so we can send it keystrokes:

$wshell.AppActivate($a.id)

给它几秒钟,让那个窗口向前移动.我选择了 5,但如果你的机器没有压力,2 可能就足够了:

Give it a few seconds to bring that window forward. I chose 5, but if your machine isn't stressed, 2 is probably enough:

Start-Sleep 5

现在开始告诉它你想发送什么密钥.这里的语法是这样的:() 中的内容就是将要发送的内容.单引号中的位置是要发送的击键,逗号后面是您希望它在继续之前等待多长时间.假设第一个屏幕是下一步",您可以通过告诉 PowerShell 发送 ENTER 键并等待 5 秒来发送您的第一个命令:

Now start telling it what keys you want to send. The syntax here is this: whatever is in the () is what will be sent. The position in the single-quote is the keystroke to send, after the comma is how long you want it to wait before proceeding. Assuming the first screen is "Next" you can send your first command by telling PowerShell to send the ENTER key and wait 5 seconds:

$wshell.SendKeys('~',5)

等待功能是可选的,但就您的目的而言,您肯定会想要它.(如果你不想要它 $wshell.SendKeys('~') 会发送 ENTER 键并立即移动到下一个命令.)

The wait function is optional, but for your purposes, you're definitely going to want it. (If you don't want it $wshell.SendKeys('~') would send the ENTER key and immediately move to the next command.)

手动完成卸载,使用所有击键,对于您发送的任何击键,请注意在加载下一部分卸载之前需要多长时间,并等待比使用脚本更长的时间(例如,如果它处理你的 ENTER 键瞬间,我会让它等待 3 或 5 秒,然后它才会发送下一个命令.如果加载需要 5 秒,我会告诉它在发送下一个命令之前等待 10 秒).

Walk through the uninstallation yourself manually, using all keystrokes, and for any keystroke you send, pay attention to how long it takes before the next part of uninstallation is loaded, and wait longer than that with your script (e.g. if it processes your ENTER key instantaneously, I'd have it wait 3 or 5 seconds before it sends the next command. If it takes 5 seconds to load, I'd tell it to wait 10 seconds before sending the next command).

字母是字母,数字是数字.大多数非命令只是分配给它们的键(意味着如果你想输入K",你的命令就是 $wshell.SendKeys('K')) 你可以得到特定此处的键:https://msdn.microsoft.com/en-us/library/office/aa202943(v=office.10).aspx.

Letters are letters, and numbers are numbers. Most non-commands are just assigned to their keys (meaning if you want to type "K" your command would just be $wshell.SendKeys('K')) You can get the rundown for the specific keys here: https://msdn.microsoft.com/en-us/library/office/aa202943(v=office.10).aspx.

这篇关于Powershell:卸载提示用户输入的软件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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