Skip to content

Commit

Permalink
bring back powershell script when conn isnt local.
Browse files Browse the repository at this point in the history
  • Loading branch information
preslavgerchev committed Jun 6, 2024
1 parent c677035 commit 66d6887
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion providers/os/resources/packages/windows_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ const (
Defender
)

const installedAppsScript = `
Get-ItemProperty (@(
'HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*',
'HKCU:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*',
'HKLM:\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*',
'HKCU:\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\*'
) | Where-Object { Test-Path $_ }) |
Select-Object -Property DisplayName,DisplayVersion,Publisher,EstimatedSize,InstallSource,UninstallString | ConvertTo-Json -Compress
`

var (
WINDOWS_QUERY_HOTFIXES = `Get-HotFix | Select-Object -Property Status, Description, HotFixId, Caption, InstalledOn, InstalledBy | ConvertTo-Json`
WINDOWS_QUERY_APPX_PACKAGES = `Get-AppxPackage -AllUsers | Select Name, PackageFullName, Architecture, Version, Publisher | ConvertTo-Json`
Expand Down Expand Up @@ -204,7 +214,7 @@ func (w *WinPkgManager) Format() string {
return "win"
}

func (w *WinPkgManager) getInstalledApps() ([]Package, error) {
func (w *WinPkgManager) getLocalInstalledApps() ([]Package, error) {
pkgs := []string{
"HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
"HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
Expand All @@ -230,6 +240,18 @@ func (w *WinPkgManager) getInstalledApps() ([]Package, error) {
return packages, nil
}

func (w *WinPkgManager) getInstalledApps() ([]Package, error) {
if w.conn.Type() == shared.Type_Local {
return w.getLocalInstalledApps()
}

cmd, err := w.conn.RunCommand(powershell.Wrap(installedAppsScript))
if err != nil {
return nil, fmt.Errorf("could not read app package list")
}
return ParseWindowsAppPackages(cmd.Stdout)
}

func (w *WinPkgManager) getPackageFromRegistryKey(key registry.RegistryKeyChild) *Package {
items, err := registry.GetNativeRegistryKeyItems(key.Path + "\\" + key.Name)
if err != nil {
Expand Down

0 comments on commit 66d6887

Please sign in to comment.