How to check if asp.net mvc 3 is installed?
I'm trying to write a powershell script that would install asp.net mvc 3 if it is not already installed. How do i che开发者_C百科ck if a specific version of asp.net mvc 3 is installed?
I think you can't change the location of the install folder, so you could probably just:
test-path "${Env:ProgramFiles(x86)}\Microsoft ASP.NET\ASP.NET MVC 3"
Another way (unfortunately quite a bit slower) is to query WMI:
$res = Get-WmiObject Win32_Product | Where {$_.Name -match 'ASP\.NET MVC 3'}
if ($res -ne $null) { ... }
I got curious, and made a Win32_AddRemovePrograms class http://poshcode.org/2470 ... that works, but honestly, you don't need that to check on a specific product, you can just look for that product's ID in the registry.
test-path "hklm:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{DCDEC776-BADD-48B9-8F9A-DFF513C3D7FA}"
Where {DCDEC776-BADD-48B9-8F9A-DFF513C3D7FA} is the product ID for Asp.net MVC 3. You could double check to make sure by checking the display name for it:
(Get-ItemProperty "hklm:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{DCDEC776-BADD-48B9-8F9A-DFF513C3D7FA}" DisplayName).DisplayName -eq "Microsoft ASP.NET MVC 3"
精彩评论