I'm working on a universal uninstaller for Java and need some help with how to properly call msiexec to uninstall versions that violate Oracle's licensing terms. My script identifies which versions of Java are forbidden, retrieves the associated MSIID, and constructs the correct command to run msiexec.
While I can see the expected command format in the task manager, the process doesn't seem to do anything—it just sits there, using 0KB of memory. However, if I manually copy and run the generated command in the command prompt, it successfully uninstalls the program. What could I be missing in my approach?
3 Answers
Try using an argument array when calling msiexec. Also, switch the '/q' flag to '/qn' for a complete silent install without any user window. This should help the process run without hanging.
When dealing with CLI tools, the key is finding what works best for your specific situation. Depending on the context (like whether running it locally or remotely), different methods can yield different results. If you want a robust solution, consider using PSADT which is a standardized wrapper for these tasks. Also, I suggest updating your code to this:
```powershell
if ($finding.Forbidden) {
Write-Host "Starting removal of '$($finding.Name)'"
$logpath = 'C:temp{0}_Uninstall_MSI.log' -f $finding.Name -replace ' ', '_'
$procParam = @{
FilePath = 'msiexec'
Wait = $true
WindowStyle = 'Hidden'
ArgumentList = @(
'/X {0}' -f $finding.msiid,
'ALLUSERS=1',
'REBOOT=REALLYSUPPRESS',
'/lvx* {0}' -f $logpath
)
}
Start-Process @procParam
}
```
This organization improves readability and functionality! Be sure to give it a try!
Keep in mind that running commands in cmd and through management tools like Intune can behave differently. Intune typically runs as a system account, so you might need to add the '/quiet' or '/qn' flag to eliminate user prompts. Otherwise, the uninstaller may be waiting for user interaction that can't happen in that context. Using psexec could help you test the command line as a system.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically