Skip to content

Commit 1045082

Browse files
committed
add javaruntime-preventasktoolbar
1 parent ece2a37 commit 1045082

File tree

4 files changed

+105
-0
lines changed

4 files changed

+105
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
3+
<metadata>
4+
<id>javaruntime-preventasktoolbar</id>
5+
<version>1.0</version>
6+
<title>Prevent Ask.com toolbar installation by Java</title>
7+
<authors>Danilo Roascio</authors>
8+
<owners>Jakub Bereżański</owners>
9+
<projectUrl>http://superuser.com/a/562869/130416</projectUrl>
10+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
11+
<description>This package sets a registry key that causes the Java Runtime Environment installer program to skip offering to install the Ask.com toolbar adware (and possibly other future unwanted software).
12+
This is particularily relevant for Java updates, which also try to install that toolbar.</description>
13+
<summary>Prevent Java installer/updater from offering to install the Ask.com toolbar</summary>
14+
<tags>java ask toolbar disable prevent adware update admin</tags>
15+
</metadata>
16+
</package>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
[CmdletBinding(SupportsShouldProcess = $true)]
2+
Param
3+
(
4+
[switch] $Disable
5+
)
6+
7+
End
8+
{
9+
$ErrorActionPreference = 'Stop'
10+
Set-StrictMode -Version 2
11+
$keyPath = 'HKLM:\SOFTWARE\JavaSoft'
12+
$keyPathWow = 'HKLM:\SOFTWARE\Wow6432Node\JavaSoft'
13+
14+
$is64 = [IntPtr]::Size -eq 8
15+
Write-Debug "Set-JavaAskToolbarPrevention Disable: $Disable Is64: $is64"
16+
17+
function Prevent-AskToolbar($targetPath)
18+
{
19+
Write-Debug "Preventing Ask toolbar installation (path: $targetPath)"
20+
if (-not (Test-Path $targetPath)) {
21+
New-Item $targetPath | Out-Null
22+
}
23+
24+
# in WhatIf mode, Set-ItemProperty would fail if the key does not exist; simulate its output
25+
if ($PSCmdlet.ShouldProcess("Item: $targetPath Property: SPONSORS", 'Set Property')) {
26+
Set-ItemProperty -LiteralPath $targetPath -Name 'SPONSORS' -Value 'DISABLE'
27+
}
28+
}
29+
30+
function Restore-AskToolbar($targetPath)
31+
{
32+
Write-Debug "Reenabling Ask toolbar installation (path: $targetPath)"
33+
Get-Item $targetPath -ErrorAction SilentlyContinue | Remove-ItemProperty -Name 'SPONSORS' -ErrorAction SilentlyContinue
34+
}
35+
36+
if ($Disable) {
37+
Restore-AskToolbar $keyPath
38+
if ($is64) {
39+
Restore-AskToolbar $keyPathWow
40+
}
41+
} else {
42+
Prevent-AskToolbar $keyPath
43+
if ($is64) {
44+
Prevent-AskToolbar $keyPathWow
45+
}
46+
}
47+
}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
try
2+
{
3+
$ErrorActionPreference = 'Stop'
4+
Set-StrictMode -Version 2
5+
6+
$is64 = Get-ProcessorBits -eq 64
7+
if ($is64 -and ([IntPtr]::Size -eq 4)) {
8+
# no way to access 64-bit registry when running under WOW64 and PS 2.0 (.NET 2.0)
9+
throw "This package cannot be fully installed using 32-bit PowerShell on a 64-bit system. Please install this package using 64-bit PowerShell."
10+
}
11+
12+
$scriptDir = Split-Path $MyInvocation.MyCommand.Path
13+
Start-ChocolateyProcessAsAdmin -statements "$scriptDir\Set-JavaAskToolbarPrevention.ps1" -minimized -noSleep
14+
15+
Write-ChocolateySuccess 'javaruntime-preventasktoolbar'
16+
}
17+
catch
18+
{
19+
Write-ChocolateyFailure 'javaruntime-preventasktoolbar' $($_.Exception.Message)
20+
throw
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
try
2+
{
3+
$ErrorActionPreference = 'Stop'
4+
Set-StrictMode -Version 2
5+
6+
$is64 = Get-ProcessorBits -eq 64
7+
if ($is64 -and ([IntPtr]::Size -eq 4)) {
8+
# no way to access 64-bit registry when running under WOW64 and PS 2.0 (.NET 2.0)
9+
throw "This package cannot be fully uninstalled using 32-bit PowerShell on a 64-bit system. Please uninstall this package using 64-bit PowerShell."
10+
}
11+
12+
$scriptDir = Split-Path $MyInvocation.MyCommand.Path
13+
Start-ChocolateyProcessAsAdmin -statements "$scriptDir\Set-JavaAskToolbarPrevention.ps1 -Disable" -minimized -noSleep
14+
15+
Write-ChocolateySuccess 'javaruntime-preventasktoolbar'
16+
}
17+
catch
18+
{
19+
Write-ChocolateyFailure 'javaruntime-preventasktoolbar' $($_.Exception.Message)
20+
throw
21+
}

0 commit comments

Comments
 (0)