我想获取系统中安装的edge和chrome浏览器的exe文件的路径, 使用gpt问了十几轮, 都没有搞到稳定的方法, 求路过大佬支招
方法3可以, 但是在自定义安装路径时就不行了, 方法4不行, 而且太慢了
Gpt的方法有如下:
1.不行!- # 查找 Google Chrome 的安装路径
- $chromePath = Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\Google Chrome" -Name "InstallLocation" -ErrorAction SilentlyContinue
- if ($chromePath) {
- Write-Host "Google Chrome 安装路径: $($chromePath.InstallLocation)\chrome.exe"
- }
-
- # 查找 Microsoft Edge 的安装路径
- $edgePath = Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Edge" -Name "InstallLocation" -ErrorAction SilentlyContinue
- if ($edgePath) {
- Write-Host "Microsoft Edge 安装路径: $($edgePath.InstallLocation)\msedge.exe"
- }
复制代码 2.不行!- # 查找 Google Chrome 的路径
- $chrome = Get-Command chrome -ErrorAction SilentlyContinue
- if ($chrome) {
- Write-Host "Google Chrome 的路径: $($chrome.Source)"
- }
-
- # 查找 Microsoft Edge 的路径
- $edge = Get-Command msedge -ErrorAction SilentlyContinue
- if ($edge) {
- Write-Host "Microsoft Edge 的路径: $($edge.Source)"
- }
复制代码 3.可以, 但是有时用户会自定义安装目录, 就不行了- # 检查是否存在 Google Chrome
- if (Test-Path "C:\Program Files\Google\Chrome\Application\chrome.exe") {
- Write-Host "Google Chrome 路径: C:\Program Files\Google\Chrome\Application\chrome.exe"
- }
-
- # 检查是否存在 Microsoft Edge
- if (Test-Path "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe") {
- Write-Host "Microsoft Edge 路径: C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
- }
复制代码 4.不行!- # 使用 WMI 查询安装的程序
- $installedApps = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -match "chrome|firefox|msedge|iexplore" }
-
- foreach ($app in $installedApps) {
- Write-Host "$($app.Name) 安装路径: $($app.InstallLocation)\$($app.Name).exe"
- }
复制代码
|