据我所知,没有确定的方法来确定用户是否安装了chorme
# Check both the Program Files and AppData directories for Chrome installation
$paths = @(
"$env:ProgramFiles\Google\Chrome\Application\chrome.exe",
"$env:ProgramFiles(x86)\Google\Chrome\Application\chrome.exe",
"$env:LOCALAPPDATA\Google\Chrome\Application\chrome.exe"
)
$chromeInstalled = $false
# Iterate through the paths and check if the Chrome executable exists
foreach ($path in $paths) {
if (Test-Path $path) {
$chromeInstalled = $true
break
}
}
或者你也可以检查它是否安装在注册表中
# Function to check if Chrome is installed in the registry
function Check-ChromeInstallation {
$paths = @(
"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*",
"HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*",
"HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*"
)
foreach ($path in $paths) {
$items = Get-ItemProperty $path
foreach ($item in $items) {
if ($item.DisplayName -like "*Google Chrome*") {
return $true
}
}
}
return $false
}