Skip to content

Commit 57acec3

Browse files
committed
remove unnecessary usage of Get-WmiObject
#11
1 parent 823f43a commit 57acec3

File tree

10 files changed

+134
-164
lines changed

10 files changed

+134
-164
lines changed

automatic/fv.install/tools/chocolateyInstall.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
$packageName = '{{PackageName}}'
2+
$url = '{{DownloadUrlx64}}'
3+
$checksum = '{{Checksum}}'
4+
$checksumType = 'sha1'
25
$installerType = 'msi'
36
$partialInstallArgs = '/quiet /qn /norestart TARGETDIR='
7+
48
# get value for TARGETDIR based on Wow6432node arch
5-
$is64bit = (Get-WmiObject Win32_Processor).AddressWidth -eq 64
6-
if ($is64bit) {
9+
if (Get-ProcessorBits 64) {
710
$installPath = ${Env:ProgramFiles(x86)}
811
} else {
912
$installPath = $Env:ProgramFiles
@@ -12,9 +15,6 @@ if ($is64bit) {
1215
$installPath = Join-Path $installPath 'FileVerifier++'
1316
# arguments presented to 'msi -i' via Install-ChocolateyPackage
1417
$installArgs = $($partialInstallArgs + '"' + $installPath + '"')
15-
$url = '{{DownloadUrlx64}}'
16-
$checksum = '{{Checksum}}'
17-
$checksumType = 'sha1'
1818
$validExitCodes = @(0)
1919

2020
Install-ChocolateyPackage -PackageName "$packageName" `
Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
1-
try {
2-
$packageName = '{{PackageName}}'
3-
$fileType = 'exe'
4-
$silentArgs = '/S'
5-
$validExitCodes = @(0)
6-
$scriptPath = Split-Path -parent $MyInvocation.MyCommand.Definition
7-
$ahkFile = "$scriptPath\$packageName.ahk"
8-
$processor = Get-WmiObject Win32_Processor
9-
$is64bit = $processor.AddressWidth -eq 64
10-
if ($is64bit) {
11-
$unPath = 'HKLM:SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
12-
$installPath = ${env:ProgramFiles(x86)}
13-
} else {
14-
$unPath = 'HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
15-
$installPath = $Env:ProgramFiles
16-
}
17-
Start-Process 'AutoHotKey' $ahkFile
18-
$unFile = (Get-ItemProperty $unPath\* | Where-Object {$_.DisplayName -like "$packageName*"}).UninstallString
19-
Uninstall-ChocolateyPackage "$packageName" "$fileType" "$silentArgs" "$unFile" -validExitCodes "$validExitCodes"
20-
$cleanup = gci -re $installPath\$packageName* | ?{ -not $_.PSIsContainer } | measure-object -sum -property Length
21-
if ($cleanup -eq $null) {
22-
Remove-Item -Recurse -Force $installPath\$packageName*
23-
}
24-
} catch {
25-
throw $_.Exception
26-
}
1+
$packageName = '{{PackageName}}'
2+
$packageSearch = "GCstar"
3+
$installerType = 'exe'
4+
$silentArgs = '/S'
5+
$validExitCodes = @(0)
6+
$scriptPath = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
7+
$ahkFile = "$scriptPath\$packageName.ahk"
8+
$ahkRun = "$Env:Temp\$(Get-Random).ahk"
9+
Copy-Item $ahkFile $ahkRun -Force
10+
Start-Process 'AutoHotKey' "$ahkRun"
11+
Get-ItemProperty -Path @( 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*',
12+
'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*',
13+
'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' ) `
14+
-ErrorAction:SilentlyContinue `
15+
| Where-Object { $_.DisplayName -like "$packageSearch*" } `
16+
| ForEach-Object { Uninstall-ChocolateyPackage -PackageName "$packageName" `
17+
-FileType "$installerType" `
18+
-SilentArgs "$($silentArgs)" `
19+
-File "$($_.UninstallString)" `
20+
-ValidExitCodes $validExitCodes }
21+
Remove-Item "$ahkRun" -Force
Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
try {
2-
$packageName = '{{PackageName}}'
3-
$fileType = 'exe'
4-
$silentArgs = '/S'
5-
$validExitCodes = @(0)
6-
$processor = Get-WmiObject Win32_Processor
7-
$is64bit = $processor.AddressWidth -eq 64
8-
if ($is64bit) {
9-
$unPath = 'HKLM:SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
10-
$installPath = ${Env:ProgramFiles(x86)}
11-
} else {
12-
$unPath = 'HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
13-
$installPath = $Env:ProgramFiles
14-
}
15-
$unFile = (Get-ItemProperty $unPath\$packageName* UninstallString).UninstallString
16-
Uninstall-ChocolateyPackage "$packageName" "$fileType" "$silentArgs" "$unFile" -validExitCodes "$validExitCodes"
17-
} catch {
18-
throw $_.Exception
19-
}
1+
$packageName = '{{PackageName}}'
2+
$packageSearch = "iTALC"
3+
$installerType = 'exe'
4+
$silentArgs = '/S'
5+
$validExitCodes = @(0)
6+
Get-ItemProperty -Path @( 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*',
7+
'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*',
8+
'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' ) `
9+
-ErrorAction:SilentlyContinue `
10+
| Where-Object { $_.DisplayName -like "$packageSearch" } `
11+
| ForEach-Object { Uninstall-ChocolateyPackage -PackageName "$packageName" `
12+
-FileType "$installerType" `
13+
-SilentArgs "$($silentArgs)" `
14+
-File "$($_.UninstallString)" `
15+
-ValidExitCodes $validExitCodes }
Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
try {
2-
$packageName = '{{PackageName}}'
3-
$fileType = 'exe'
4-
$silentArgs = '/S'
5-
$validExitCodes = @(0)
6-
$scriptPath = Split-Path -parent $MyInvocation.MyCommand.Definition
7-
$ahkFile = "$scriptPath\$packageName.ahk"
8-
$ahkRun = "$Env:Temp\$(Get-Random).ahk"
9-
Copy-Item $ahkFile $ahkRun -Force
10-
$processor = Get-WmiObject Win32_Processor
11-
$is64bit = $processor.AddressWidth -eq 64
12-
if ($is64bit) {
13-
$unPath = 'HKLM:SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
14-
} else {
15-
$unPath = 'HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
16-
}
17-
Start-Process 'AutoHotKey' "$ahkRun"
18-
$unFile = (Get-ItemProperty $unPath\$packageName* UninstallString).UninstallString
19-
Uninstall-ChocolateyPackage "$packageName" "$fileType" "$silentArgs" "$unFile" -validExitCodes $validExitCodes
20-
Remove-Item "$ahkRun"
21-
} catch {
22-
throw $_.Exception
23-
}
1+
$packageName = '{{PackageName}}'
2+
$packageSearch = "JStock"
3+
$installerType = 'exe'
4+
$silentArgs = '/S'
5+
$validExitCodes = @(0)
6+
$scriptPath = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
7+
$ahkFile = "$scriptPath\$packageName.ahk"
8+
$ahkRun = "$Env:Temp\$(Get-Random).ahk"
9+
Copy-Item $ahkFile $ahkRun -Force
10+
Start-Process 'AutoHotKey' "$ahkRun"
11+
Get-ItemProperty -Path @( 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*',
12+
'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*',
13+
'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' ) `
14+
-ErrorAction:SilentlyContinue `
15+
| Where-Object { $_.DisplayName -like "$packageSearch*" } `
16+
| ForEach-Object { Uninstall-ChocolateyPackage -PackageName "$packageName" `
17+
-FileType "$installerType" `
18+
-SilentArgs "$($silentArgs)" `
19+
-File "$($_.UninstallString)" `
20+
-ValidExitCodes $validExitCodes }
21+
Remove-Item "$ahkRun" -Force
Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
$packageName = '{{PackageName}}'
2-
$installerType = 'msi'
3-
$partialInstallArgs = '/quiet /qn /norestart TARGETDIR='
4-
$is64bit = (Get-WmiObject Win32_Processor).AddressWidth -eq 64
5-
if ($is64bit) {$installPath = ${Env:ProgramFiles(x86)}} else {$installPath = $Env:ProgramFiles}
6-
$installArgs = $($partialInstallArgs + '"' + $installPath + '"')
72
# due to limitations of Ketarin/chocopkgup when using repos like sf.net:
83
$url = '{{DownloadUrlx64}}'
9-
$checksum = '{{Checksumx64}}'
4+
$checksum = '{{Checksum}}'
105
$checksumType = 'sha1'
6+
$installerType = 'msi'
7+
$partialInstallArgs = '/quiet /qn /norestart TARGETDIR='
8+
if (Get-ProcessorBits 64) {
9+
$installPath = ${Env:ProgramFiles(x86)}
10+
} else {
11+
$installPath = $Env:ProgramFiles
12+
}
13+
$installArgs = $($partialInstallArgs + '"' + $installPath + '"')
1114
$validExitCodes = @(0)
12-
13-
Install-ChocolateyPackage "$packageName" "$installerType" "$installArgs" "$url" -validExitCodes $validExitCodes -Checksum "$checksum" -ChecksumType "$checksumType"
15+
Install-ChocolateyPackage -PackageName "$packageName" `
16+
-FileType "$installerType" `
17+
-SilentArgs "$silentArgs" `
18+
-Url "$url" `
19+
-ValidExitCodes $validExitCodes `
20+
-Checksum "$checksum" `
21+
-ChecksumType "$checksumType"
Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
$packageName = '{{PackageName}}'
2-
$installerType = 'msi'
3-
$partialInstallArgs = '/quiet /qn /norestart TARGETDIR='
4-
$is64bit = (Get-WmiObject Win32_Processor).AddressWidth -eq 64
5-
if ($is64bit) {$installPath = ${Env:ProgramFiles(x86)}} else {$installPath = $Env:ProgramFiles}
6-
$installArgs = $($partialInstallArgs + '"' + $installPath + '"')
72
# due to limitations of Ketarin/chocopkgup when using repos like sf.net:
83
$url = '{{DownloadUrlx64}}'
94
$checksum = '{{Checksum}}'
105
$checksumType = 'sha1'
6+
$installerType = 'msi'
7+
$partialInstallArgs = '/quiet /qn /norestart TARGETDIR='
8+
if (Get-ProcessorBits 64) {
9+
$installPath = ${Env:ProgramFiles(x86)}
10+
} else {
11+
$installPath = $Env:ProgramFiles
12+
}
13+
$installArgs = $($partialInstallArgs + '"' + $installPath + '"')
1114
$validExitCodes = @(0)
12-
13-
Install-ChocolateyPackage "$packageName" "$installerType" "$installArgs" "$url" -validExitCodes "$validExitCodes" -checksum "$checksum" -checksumType "$checksumType"
14-
15+
Install-ChocolateyPackage -PackageName "$packageName" `
16+
-FileType "$installerType" `
17+
-SilentArgs "$silentArgs" `
18+
-Url "$url" `
19+
-ValidExitCodes $validExitCodes `
20+
-Checksum "$checksum" `
21+
-ChecksumType "$checksumType"
Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
try {
2-
$packageName = '{{PackageName}}'
3-
$fileType = 'exe'
4-
$silentArgs = '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART'
5-
$validExitCodes = @(0)
6-
7-
$processor = Get-WmiObject Win32_Processor
8-
$is64bit = $processor.AddressWidth -eq 64
9-
if ($is64bit) {
10-
$unFile = (Get-ItemProperty HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | select DisplayName, UninstallString | Where-Object {$_.DisplayName -like "$packageName*"}).UninstallString
11-
} else {
12-
$unFile = (Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* | select DisplayName, UninstallString | Where-Object {$_.DisplayName -like "$packageName*"}).UninstallString
13-
}
14-
Uninstall-ChocolateyPackage $packageName $fileType $silentArgs $file -validExitCodes $validExitCodes
15-
} catch {
16-
throw $_.Exception
17-
}
1+
$packageName = '{{PackageName}}'
2+
$packageSearch = "PeerBlock"
3+
$installerType = 'exe'
4+
$silentArgs = '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-'
5+
$validExitCodes = @(0)
6+
Get-ItemProperty -Path @( 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*',
7+
'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*',
8+
'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' ) `
9+
-ErrorAction:SilentlyContinue `
10+
| Where-Object { $_.DisplayName -like "$packageSearch*" } `
11+
| ForEach-Object { Uninstall-ChocolateyPackage -PackageName "$packageName" `
12+
-FileType "$installerType" `
13+
-SilentArgs "$($silentArgs)" `
14+
-File "$($_.UninstallString)" `
15+
-ValidExitCodes $validExitCodes }
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
$packageName = '{{PackageName}}'
2+
# due to limitations of Ketarin/chocopkgup when using repos like sf.net:
3+
$url = '{{DownloadUrlx64}}'
4+
$checksum = '{{Checksum}}'
5+
$checksumType = 'sha1'
26
$installerType = 'msi'
37
$partialInstallArgs = '/quiet /qn /norestart TARGETDIR='
4-
$is64bit = (Get-WmiObject Win32_Processor).AddressWidth -eq 64
5-
if ($is64bit) {$installPath = ${Env:ProgramFiles(x86)}} else {$installPath = $Env:ProgramFiles}
8+
if (Get-ProcessorBits 64) {
9+
$installPath = ${Env:ProgramFiles(x86)}
10+
} else {
11+
$installPath = $Env:ProgramFiles
12+
}
613
$installArgs = $($partialInstallArgs + '"' + $installPath + '"')
7-
$url = '{{DownloadUrlx64}}'
8-
$checksum = '{{Checksumx64}}'
9-
$checksumType = 'sha1'
1014
$validExitCodes = @(0)
11-
1215
Install-ChocolateyPackage -PackageName "$packageName" `
1316
-FileType "$installerType" `
14-
-Url "$url" `
1517
-SilentArgs "$silentArgs" `
18+
-Url "$url" `
1619
-ValidExitCodes $validExitCodes `
1720
-Checksum "$checksum" `
18-
-ChecksumType "$checksumType"
21+
-ChecksumType "$checksumType"
Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
try {
2-
$packageName = '{{PackageName}}'
3-
$fileType = 'exe'
4-
$silentArgs = '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART'
5-
$validExitCodes = @(0)
6-
$processor = Get-WmiObject Win32_Processor
7-
$is64bit = $processor.AddressWidth -eq 64
8-
if ($is64bit) {
9-
$unPath = 'HKLM:SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
10-
} else {
11-
$unPath = 'HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
12-
}
13-
$unFile = (Get-ItemProperty $unPath\* | Where-Object {$_.DisplayName -like "$packageName*"}).UninstallString
14-
Uninstall-ChocolateyPackage "$packageName" "$fileType" "$silentArgs" "$unFile" -validExitCodes "$validExitCodes"
15-
} catch {
16-
throw $_.Exception
17-
}
1+
$packageName = '{{PackageName}}'
2+
$packageSearch = "QuiteRSS"
3+
$installerType = 'exe'
4+
$silentArgs = '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-'
5+
$validExitCodes = @(0)
6+
Get-ItemProperty -Path @( 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*',
7+
'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*',
8+
'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' ) `
9+
-ErrorAction:SilentlyContinue `
10+
| Where-Object { $_.DisplayName -like "$packageSearch*" } `
11+
| ForEach-Object { Uninstall-ChocolateyPackage -PackageName "$packageName" `
12+
-FileType "$installerType" `
13+
-SilentArgs "$($silentArgs)" `
14+
-File "$($_.UninstallString)" `
15+
-ValidExitCodes $validExitCodes }

automatic/totalcommander/tools/chocolateyInstall.ps1

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,8 @@ $url64 = $url # 64bit URL here or just use the same as $url
77
$silentArgs = '' # "/s /S /q /Q /quiet /silent /SILENT /VERYSILENT" # try any of these to get the silent installer #msi is always /quiet
88
$validExitCodes = @(0) #please insert other valid exit codes here, exit codes for ms http://msdn.microsoft.com/en-us/library/aa368542(VS.85).aspx
99

10-
# main helpers - these have error handling tucked into them already
11-
# installer, will assert administrative rights
1210
Install-ChocolateyPackage "$packageName" "$installerType" "$silentArgs" "$url" "$url64" -validExitCodes $validExitCodes
13-
# download and unpack a zip file
14-
# Install-ChocolateyZipPackage "$packageName" "$url" "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" "$url64"
1511

16-
#try { #error handling is only necessary if you need to do anything in addition to/instead of the main helpers
17-
# other helpers - using any of these means you want to uncomment the error handling up top and at bottom.
18-
# downloader that the main helpers use to download items
19-
#Get-ChocolateyWebFile "$packageName" 'DOWNLOAD_TO_FILE_FULL_PATH' "$url" "$url64"
20-
# installer, will assert administrative rights - used by Install-ChocolateyPackage
21-
#Install-ChocolateyInstallPackage "$packageName" "$installerType" "$silentArgs" '_FULLFILEPATH_' -validExitCodes $validExitCodes
22-
# unzips a file to the specified location - auto overwrites existing content
23-
#Get-ChocolateyUnzip "FULL_LOCATION_TO_ZIP.zip" "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
24-
# Runs processes asserting UAC, will assert administrative rights - used by Install-ChocolateyInstallPackage
25-
#Start-ChocolateyProcessAsAdmin 'STATEMENTS_TO_RUN' 'Optional_Application_If_Not_PowerShell' -validExitCodes $validExitCodes
26-
# add specific folders to the path - any executables found in the chocolatey package folder will already be on the path. This is used in addition to that or for cases when a native installer doesn't add things to the path.
27-
#Install-ChocolateyPath 'LOCATION_TO_ADD_TO_PATH' 'User_OR_Machine' # Machine will assert administrative rights
28-
# add specific files as shortcuts to the desktop
29-
#$target = Join-Path $MyInvocation.MyCommand.Definition "$($packageName).exe"
30-
#Install-ChocolateyDesktopLink $target
31-
32-
#------- ADDITIONAL SETUP -------#
33-
# make sure to uncomment the error handling if you have additional setup to do
34-
35-
#$processor = Get-WmiObject Win32_Processor
36-
#$is64bit = $processor.AddressWidth -eq 64
37-
38-
39-
# the following is all part of error handling
40-
#Write-ChocolateySuccess "$packageName"
41-
#} catch {
42-
#Write-ChocolateyFailure "$packageName" "$($_.Exception.Message)"
43-
#throw
44-
#}
4512

4613

4714

0 commit comments

Comments
 (0)