up vote -3 down vote favorite

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 toolbar uninstaller share asked Nov 11 '15 at 12:50 Nick 106 1 7 1   Hi, 1. Please show some code 2. malwaretips.com/blogs/pdfforge-toolbar-removal I don't think "uninstalling" this malware with the built-in "uninstaller" will be effective nor enough –  sodawillow Nov 11 '15 at 19:28      Why is this being downvoted? –  KlaymenDK Nov 12 '15 at 20:51      I wish I knew... Thank you for looking :) –  Nick Nov 13 '15 at 15:23 add a comment  | 

1 Answer 1

active oldest votes up vote 1 down vote accepted

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.

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

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"}

Start the COM:

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

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

$wshell.AppActivate($a.id)

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

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)

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.)

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).

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.

share answered Nov 11 '15 at 18:22 Nate 450 1 12      And make sure NO ONE touches the workstation while this script is running! –  Nate Nov 11 '15 at 18:25      This is exactly what I needed, thank you so much! –  Nick Nov 12 '15 at 19:48      I do what I can. :) –  Nate Nov 12 '15 at 20:59 add a comment  | 

Your Answer

  draft saved draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Post as a guest

Name Email

Post as a guest

Name Email discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged powershell toolbar uninstaller or ask your own question.

快照源:http://www.cnblogs.com/beidan/p/5353117.html