代码之家  ›  专栏  ›  技术社区  ›  Uhmazing34

Powershell脚本,用于检测用户是否安装了Chrome?

  •  0
  • Uhmazing34  · 技术社区  · 2 年前

    我们可以看到,有些电脑安装了谷歌浏览器,但它没有安装在C:\Program Files下。一些用户已经在他们的本地应用程序数据文件夹中安装了Chrome,因此我们无法集中管理(一些计算机被多个用户使用)。

    有人可能有Powershell脚本来检测哪些用户在其本地AppData文件夹和/或在哪台计算机上安装了Chrome吗?

    我尝试使用这个Powershell脚本,但不幸的是,它没有找到任何内容:

    Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall* | Where-Object {$_.DisplayName -eq 'Google Chrome'}
    

    提前谢谢!

    1 回复  |  直到 2 年前
        1
  •  0
  •   Felpower    2 年前

    据我所知,没有确定的方法来确定用户是否安装了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
    }