Skip to content

Commit

Permalink
remove unnecessary usage of Get-WmiObject
Browse files Browse the repository at this point in the history
  • Loading branch information
dtgm committed Jul 2, 2015
1 parent 214975e commit 6207f45
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 164 deletions.
10 changes: 5 additions & 5 deletions automatic/fv.install/tools/chocolateyInstall.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
$packageName = '{{PackageName}}'
$url = '{{DownloadUrlx64}}'
$checksum = '{{Checksum}}'
$checksumType = 'sha1'
$installerType = 'msi'
$partialInstallArgs = '/quiet /qn /norestart TARGETDIR='

# get value for TARGETDIR based on Wow6432node arch
$is64bit = (Get-WmiObject Win32_Processor).AddressWidth -eq 64
if ($is64bit) {
if (Get-ProcessorBits 64) {
$installPath = ${Env:ProgramFiles(x86)}
} else {
$installPath = $Env:ProgramFiles
Expand All @@ -12,9 +15,6 @@ if ($is64bit) {
$installPath = Join-Path $installPath 'FileVerifier++'
# arguments presented to 'msi -i' via Install-ChocolateyPackage
$installArgs = $($partialInstallArgs + '"' + $installPath + '"')
$url = '{{DownloadUrlx64}}'
$checksum = '{{Checksum}}'
$checksumType = 'sha1'
$validExitCodes = @(0)

Install-ChocolateyPackage -PackageName "$packageName" `
Expand Down
47 changes: 21 additions & 26 deletions automatic/gcstar/tools/chocolateyUninstall.ps1
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
try {
$packageName = '{{PackageName}}'
$fileType = 'exe'
$silentArgs = '/S'
$validExitCodes = @(0)
$scriptPath = Split-Path -parent $MyInvocation.MyCommand.Definition
$ahkFile = "$scriptPath\$packageName.ahk"
$processor = Get-WmiObject Win32_Processor
$is64bit = $processor.AddressWidth -eq 64
if ($is64bit) {
$unPath = 'HKLM:SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
$installPath = ${env:ProgramFiles(x86)}
} else {
$unPath = 'HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
$installPath = $Env:ProgramFiles
}
Start-Process 'AutoHotKey' $ahkFile
$unFile = (Get-ItemProperty $unPath\* | Where-Object {$_.DisplayName -like "$packageName*"}).UninstallString
Uninstall-ChocolateyPackage "$packageName" "$fileType" "$silentArgs" "$unFile" -validExitCodes "$validExitCodes"
$cleanup = gci -re $installPath\$packageName* | ?{ -not $_.PSIsContainer } | measure-object -sum -property Length
if ($cleanup -eq $null) {
Remove-Item -Recurse -Force $installPath\$packageName*
}
} catch {
throw $_.Exception
}
$packageName = '{{PackageName}}'
$packageSearch = "GCstar"
$installerType = 'exe'
$silentArgs = '/S'
$validExitCodes = @(0)
$scriptPath = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
$ahkFile = "$scriptPath\$packageName.ahk"
$ahkRun = "$Env:Temp\$(Get-Random).ahk"
Copy-Item $ahkFile $ahkRun -Force
Start-Process 'AutoHotKey' "$ahkRun"
Get-ItemProperty -Path @( 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*',
'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*',
'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' ) `
-ErrorAction:SilentlyContinue `
| Where-Object { $_.DisplayName -like "$packageSearch*" } `
| ForEach-Object { Uninstall-ChocolateyPackage -PackageName "$packageName" `
-FileType "$installerType" `
-SilentArgs "$($silentArgs)" `
-File "$($_.UninstallString)" `
-ValidExitCodes $validExitCodes }
Remove-Item "$ahkRun" -Force
34 changes: 15 additions & 19 deletions automatic/italc/tools/chocolateyUninstall.ps1
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
try {
$packageName = '{{PackageName}}'
$fileType = 'exe'
$silentArgs = '/S'
$validExitCodes = @(0)
$processor = Get-WmiObject Win32_Processor
$is64bit = $processor.AddressWidth -eq 64
if ($is64bit) {
$unPath = 'HKLM:SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
$installPath = ${Env:ProgramFiles(x86)}
} else {
$unPath = 'HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
$installPath = $Env:ProgramFiles
}
$unFile = (Get-ItemProperty $unPath\$packageName* UninstallString).UninstallString
Uninstall-ChocolateyPackage "$packageName" "$fileType" "$silentArgs" "$unFile" -validExitCodes "$validExitCodes"
} catch {
throw $_.Exception
}
$packageName = '{{PackageName}}'
$packageSearch = "iTALC"
$installerType = 'exe'
$silentArgs = '/S'
$validExitCodes = @(0)
Get-ItemProperty -Path @( 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*',
'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*',
'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' ) `
-ErrorAction:SilentlyContinue `
| Where-Object { $_.DisplayName -like "$packageSearch" } `
| ForEach-Object { Uninstall-ChocolateyPackage -PackageName "$packageName" `
-FileType "$installerType" `
-SilentArgs "$($silentArgs)" `
-File "$($_.UninstallString)" `
-ValidExitCodes $validExitCodes }
44 changes: 21 additions & 23 deletions automatic/jstock/tools/chocolateyUninstall.ps1
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
try {
$packageName = '{{PackageName}}'
$fileType = 'exe'
$silentArgs = '/S'
$validExitCodes = @(0)
$scriptPath = Split-Path -parent $MyInvocation.MyCommand.Definition
$ahkFile = "$scriptPath\$packageName.ahk"
$ahkRun = "$Env:Temp\$(Get-Random).ahk"
Copy-Item $ahkFile $ahkRun -Force
$processor = Get-WmiObject Win32_Processor
$is64bit = $processor.AddressWidth -eq 64
if ($is64bit) {
$unPath = 'HKLM:SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
} else {
$unPath = 'HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
}
Start-Process 'AutoHotKey' "$ahkRun"
$unFile = (Get-ItemProperty $unPath\$packageName* UninstallString).UninstallString
Uninstall-ChocolateyPackage "$packageName" "$fileType" "$silentArgs" "$unFile" -validExitCodes $validExitCodes
Remove-Item "$ahkRun"
} catch {
throw $_.Exception
}
$packageName = '{{PackageName}}'
$packageSearch = "JStock"
$installerType = 'exe'
$silentArgs = '/S'
$validExitCodes = @(0)
$scriptPath = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
$ahkFile = "$scriptPath\$packageName.ahk"
$ahkRun = "$Env:Temp\$(Get-Random).ahk"
Copy-Item $ahkFile $ahkRun -Force
Start-Process 'AutoHotKey' "$ahkRun"
Get-ItemProperty -Path @( 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*',
'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*',
'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' ) `
-ErrorAction:SilentlyContinue `
| Where-Object { $_.DisplayName -like "$packageSearch*" } `
| ForEach-Object { Uninstall-ChocolateyPackage -PackageName "$packageName" `
-FileType "$installerType" `
-SilentArgs "$($silentArgs)" `
-File "$($_.UninstallString)" `
-ValidExitCodes $validExitCodes }
Remove-Item "$ahkRun" -Force
24 changes: 16 additions & 8 deletions automatic/openproj/tools/chocolateyInstall.ps1
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
$packageName = '{{PackageName}}'
$installerType = 'msi'
$partialInstallArgs = '/quiet /qn /norestart TARGETDIR='
$is64bit = (Get-WmiObject Win32_Processor).AddressWidth -eq 64
if ($is64bit) {$installPath = ${Env:ProgramFiles(x86)}} else {$installPath = $Env:ProgramFiles}
$installArgs = $($partialInstallArgs + '"' + $installPath + '"')
# due to limitations of Ketarin/chocopkgup when using repos like sf.net:
$url = '{{DownloadUrlx64}}'
$checksum = '{{Checksumx64}}'
$checksum = '{{Checksum}}'
$checksumType = 'sha1'
$installerType = 'msi'
$partialInstallArgs = '/quiet /qn /norestart TARGETDIR='
if (Get-ProcessorBits 64) {
$installPath = ${Env:ProgramFiles(x86)}
} else {
$installPath = $Env:ProgramFiles
}
$installArgs = $($partialInstallArgs + '"' + $installPath + '"')
$validExitCodes = @(0)

Install-ChocolateyPackage "$packageName" "$installerType" "$installArgs" "$url" -validExitCodes $validExitCodes -Checksum "$checksum" -ChecksumType "$checksumType"
Install-ChocolateyPackage -PackageName "$packageName" `
-FileType "$installerType" `
-SilentArgs "$silentArgs" `
-Url "$url" `
-ValidExitCodes $validExitCodes `
-Checksum "$checksum" `
-ChecksumType "$checksumType"
23 changes: 15 additions & 8 deletions automatic/pdfedit/tools/chocolateyInstall.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
$packageName = '{{PackageName}}'
$installerType = 'msi'
$partialInstallArgs = '/quiet /qn /norestart TARGETDIR='
$is64bit = (Get-WmiObject Win32_Processor).AddressWidth -eq 64
if ($is64bit) {$installPath = ${Env:ProgramFiles(x86)}} else {$installPath = $Env:ProgramFiles}
$installArgs = $($partialInstallArgs + '"' + $installPath + '"')
# due to limitations of Ketarin/chocopkgup when using repos like sf.net:
$url = '{{DownloadUrlx64}}'
$checksum = '{{Checksum}}'
$checksumType = 'sha1'
$installerType = 'msi'
$partialInstallArgs = '/quiet /qn /norestart TARGETDIR='
if (Get-ProcessorBits 64) {
$installPath = ${Env:ProgramFiles(x86)}
} else {
$installPath = $Env:ProgramFiles
}
$installArgs = $($partialInstallArgs + '"' + $installPath + '"')
$validExitCodes = @(0)

Install-ChocolateyPackage "$packageName" "$installerType" "$installArgs" "$url" -validExitCodes "$validExitCodes" -checksum "$checksum" -checksumType "$checksumType"

Install-ChocolateyPackage -PackageName "$packageName" `
-FileType "$installerType" `
-SilentArgs "$silentArgs" `
-Url "$url" `
-ValidExitCodes $validExitCodes `
-Checksum "$checksum" `
-ChecksumType "$checksumType"
32 changes: 15 additions & 17 deletions automatic/peerblock/tools/chocolateyUninstall.ps1
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
try {
$packageName = '{{PackageName}}'
$fileType = 'exe'
$silentArgs = '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART'
$validExitCodes = @(0)

$processor = Get-WmiObject Win32_Processor
$is64bit = $processor.AddressWidth -eq 64
if ($is64bit) {
$unFile = (Get-ItemProperty HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | select DisplayName, UninstallString | Where-Object {$_.DisplayName -like "$packageName*"}).UninstallString
} else {
$unFile = (Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* | select DisplayName, UninstallString | Where-Object {$_.DisplayName -like "$packageName*"}).UninstallString
}
Uninstall-ChocolateyPackage $packageName $fileType $silentArgs $file -validExitCodes $validExitCodes
} catch {
throw $_.Exception
}
$packageName = '{{PackageName}}'
$packageSearch = "PeerBlock"
$installerType = 'exe'
$silentArgs = '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-'
$validExitCodes = @(0)
Get-ItemProperty -Path @( 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*',
'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*',
'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' ) `
-ErrorAction:SilentlyContinue `
| Where-Object { $_.DisplayName -like "$packageSearch*" } `
| ForEach-Object { Uninstall-ChocolateyPackage -PackageName "$packageName" `
-FileType "$installerType" `
-SilentArgs "$($silentArgs)" `
-File "$($_.UninstallString)" `
-ValidExitCodes $validExitCodes }
19 changes: 11 additions & 8 deletions automatic/projectlibre.install/tools/chocolateyInstall.ps1
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
$packageName = '{{PackageName}}'
# due to limitations of Ketarin/chocopkgup when using repos like sf.net:
$url = '{{DownloadUrlx64}}'
$checksum = '{{Checksum}}'
$checksumType = 'sha1'
$installerType = 'msi'
$partialInstallArgs = '/quiet /qn /norestart TARGETDIR='
$is64bit = (Get-WmiObject Win32_Processor).AddressWidth -eq 64
if ($is64bit) {$installPath = ${Env:ProgramFiles(x86)}} else {$installPath = $Env:ProgramFiles}
if (Get-ProcessorBits 64) {
$installPath = ${Env:ProgramFiles(x86)}
} else {
$installPath = $Env:ProgramFiles
}
$installArgs = $($partialInstallArgs + '"' + $installPath + '"')
$url = '{{DownloadUrlx64}}'
$checksum = '{{Checksumx64}}'
$checksumType = 'sha1'
$validExitCodes = @(0)

Install-ChocolateyPackage -PackageName "$packageName" `
-FileType "$installerType" `
-Url "$url" `
-SilentArgs "$silentArgs" `
-Url "$url" `
-ValidExitCodes $validExitCodes `
-Checksum "$checksum" `
-ChecksumType "$checksumType"
-ChecksumType "$checksumType"
32 changes: 15 additions & 17 deletions automatic/quiterss/tools/chocolateyUninstall.ps1
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
try {
$packageName = '{{PackageName}}'
$fileType = 'exe'
$silentArgs = '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART'
$validExitCodes = @(0)
$processor = Get-WmiObject Win32_Processor
$is64bit = $processor.AddressWidth -eq 64
if ($is64bit) {
$unPath = 'HKLM:SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
} else {
$unPath = 'HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
}
$unFile = (Get-ItemProperty $unPath\* | Where-Object {$_.DisplayName -like "$packageName*"}).UninstallString
Uninstall-ChocolateyPackage "$packageName" "$fileType" "$silentArgs" "$unFile" -validExitCodes "$validExitCodes"
} catch {
throw $_.Exception
}
$packageName = '{{PackageName}}'
$packageSearch = "QuiteRSS"
$installerType = 'exe'
$silentArgs = '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-'
$validExitCodes = @(0)
Get-ItemProperty -Path @( 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*',
'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*',
'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' ) `
-ErrorAction:SilentlyContinue `
| Where-Object { $_.DisplayName -like "$packageSearch*" } `
| ForEach-Object { Uninstall-ChocolateyPackage -PackageName "$packageName" `
-FileType "$installerType" `
-SilentArgs "$($silentArgs)" `
-File "$($_.UninstallString)" `
-ValidExitCodes $validExitCodes }
33 changes: 0 additions & 33 deletions automatic/totalcommander/tools/chocolateyInstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,8 @@ $url64 = $url # 64bit URL here or just use the same as $url
$silentArgs = '' # "/s /S /q /Q /quiet /silent /SILENT /VERYSILENT" # try any of these to get the silent installer #msi is always /quiet
$validExitCodes = @(0) #please insert other valid exit codes here, exit codes for ms http://msdn.microsoft.com/en-us/library/aa368542(VS.85).aspx

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

#try { #error handling is only necessary if you need to do anything in addition to/instead of the main helpers
# other helpers - using any of these means you want to uncomment the error handling up top and at bottom.
# downloader that the main helpers use to download items
#Get-ChocolateyWebFile "$packageName" 'DOWNLOAD_TO_FILE_FULL_PATH' "$url" "$url64"
# installer, will assert administrative rights - used by Install-ChocolateyPackage
#Install-ChocolateyInstallPackage "$packageName" "$installerType" "$silentArgs" '_FULLFILEPATH_' -validExitCodes $validExitCodes
# unzips a file to the specified location - auto overwrites existing content
#Get-ChocolateyUnzip "FULL_LOCATION_TO_ZIP.zip" "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
# Runs processes asserting UAC, will assert administrative rights - used by Install-ChocolateyInstallPackage
#Start-ChocolateyProcessAsAdmin 'STATEMENTS_TO_RUN' 'Optional_Application_If_Not_PowerShell' -validExitCodes $validExitCodes
# 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.
#Install-ChocolateyPath 'LOCATION_TO_ADD_TO_PATH' 'User_OR_Machine' # Machine will assert administrative rights
# add specific files as shortcuts to the desktop
#$target = Join-Path $MyInvocation.MyCommand.Definition "$($packageName).exe"
#Install-ChocolateyDesktopLink $target

#------- ADDITIONAL SETUP -------#
# make sure to uncomment the error handling if you have additional setup to do

#$processor = Get-WmiObject Win32_Processor
#$is64bit = $processor.AddressWidth -eq 64


# the following is all part of error handling
#Write-ChocolateySuccess "$packageName"
#} catch {
#Write-ChocolateyFailure "$packageName" "$($_.Exception.Message)"
#throw
#}



Expand Down

0 comments on commit 6207f45

Please sign in to comment.