0

The idea here is to uninstall a program silently. Unfortunately the program's msi is custom and executes a batch file during the uninstall process. What I am trying to do is prevent this window from displaying during the powershell uninstall script. I'm using wmi uninstall method because the msi that the program uses doesn't respond to quite or uninstall flags (/q, /x, /uninstall). I have attempted to run it as a background job but the window still appears. The script looks as follows:

start-job -scriptblock `
    {(Get-WmiObject -class Win32_Product |? {$_Name -eq "Annoying1"}).uninstall()} `
    -Name Uninstall1
$job = get-job -name Uninstall1
wait-job $job
receive-job $job

This will run mostly hidden until the uninstall job gets to the point where the batch file is executed, at which point a cmd window will appear and run. Any ideas of how to run this script without displaying extra windows?

The script is ran with -windowstyle hidden as well.

1
  • Might be a dirty solution but, provided you have the necessary permissions, you could create an "uninstall" user and start your job using the corresponding credentials. The command prompt will only show for the user currently logged in. Commented Jun 29, 2012 at 12:12

1 Answer 1

1

Be indulgent, I'am not proud of this, but I'am quite sure that if you try to localy run your script using remoting the window will not be seen by the user :

I just try :

$sess = New-PSSession -ComputerName localhost
Invoke-Command -Session $sess -ScriptBlock {calc.exe}
get-process "calc"

In your case try :

$sess = New-PSSession -ComputerName localhost
$job = Invoke-Command -Session $sess -ScriptBlock {(Get-WmiObject -class Win32_Product |? {$_Name -eq "Annoying1"}).uninstall()} -asjob -Name Uninstall1
wait-job $job
receive-job $job
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, this is an excellent idea and would do the trick but unfortunately the WinRM service that New-PSSession requires isn't enabled for our approved configuration.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.