Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
308 views
in Technique[技术] by (71.8m points)

Check if program is installed if so go to next powershell

I've googled and not found anything useful to me.

I have 4 msi files I want to install but would like to check if some of it is installed on the computer.

Example: check if program 1 is installed, if not install it and go to and install program 2. However if it's not installed, install it and go to program 2 and do the same test there.

Execute-MSI -Action Install -Path "$dirFilesProgram1"
Execute-MSI -Action Install -Path "$dirFilesProgram2"
Execute-MSI -Action Install -Path "$dirFilesProgram3"
Execute-MSI -Action Install -Path "$dirFilesProgram4"
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you know the GUID, you could test path the uninstall key. Also don't forget that if your OS is 64 bit, there will be the same key in WOW6432Node for 32 bit apps.

$uninstallkey = "HKLM:SoftwareMicrosoftWindowsCurrentVersionUninstall"
$uninstall32key = "HKLM:SoftwareWOW6432NodeMicrosoftWindowsCurrentVersionUninstall"
#Example 64-bit app
$app1guid = "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"
if (!(Test-Path "$uninstallkey$app1guid)) {Execute-MSI -Action Install -Path "$dirFilesProgram1"}
#Example 32-bit app
$app2guid = "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"
if (!(Test-Path "$uninstall32key$app2guid)) {Execute-MSI -Action Install -Path "$dirFilesProgram1"}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...