Skip to content

Commit 242b998

Browse files
committed
i Disable-URL
See SYNOPSIS/DESCRIPTION
1 parent d4ea6b4 commit 242b998

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

ps-network/Disable-URL.ps1

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
function Disable-URL {
2+
<#
3+
.SYNOPSIS
4+
Starts the URL Disabler application.
5+
6+
.DESCRIPTION
7+
This function manages the URL Disabler tool, which allows users to block specific URLs for Google Chrome, Firefox, and Chromium Edge. It supports starting the application and optionally removing temporary files after use.
8+
9+
.EXAMPLE
10+
Disable-URL -StartApplication
11+
12+
.NOTES
13+
v0.0.1
14+
#>
15+
[CmdletBinding()]
16+
param (
17+
[Parameter(Mandatory = $true, HelpMessage = "Start the URL Disabler application")]
18+
[switch]$StartApplication,
19+
20+
[Parameter(Mandatory = $false, HelpMessage = "Remove the temporary folder after the operation")]
21+
[switch]$RemoveFiles,
22+
23+
[Parameter(Mandatory = $false, HelpMessage = "URL for downloading URL Disabler tool")]
24+
[uri]$DownloadUrl = "https://www.sordum.org/files/download/url-disabler/UrlDisabler.zip",
25+
26+
[Parameter(Mandatory = $false, HelpMessage = "Path to the directory where URL Disabler tool will be downloaded and extracted")]
27+
[string]$DownloadPath = "$env:TEMP\UrlDisablerTool"
28+
)
29+
$ZipFilePath = Join-Path $DownloadPath "UrlDisabler.zip"
30+
$ExtractPath = Join-Path $DownloadPath "UrlDisabler"
31+
$Executable = Join-Path $ExtractPath "UrlDisabler.exe"
32+
try {
33+
Write-Host "Creating download directory..." -ForegroundColor Green
34+
if (-not (Test-Path -Path $DownloadPath)) {
35+
New-Item -Path $DownloadPath -ItemType Directory -Force | Out-Null
36+
}
37+
if (-not (Test-Path -Path $ZipFilePath)) {
38+
Write-Host "Downloading URL Disabler tool..." -ForegroundColor Green
39+
Invoke-WebRequest -Uri $DownloadUrl -OutFile $ZipFilePath -UseBasicParsing -Verbose
40+
if ((Get-Item $ZipFilePath).Length -eq 0) {
41+
throw "The downloaded ZIP file is empty or corrupt!"
42+
}
43+
}
44+
Write-Host "Extracting URL Disabler tool..." -ForegroundColor Green
45+
if (Test-Path -Path $ExtractPath) {
46+
Remove-Item -Path $ExtractPath -Recurse -Force -ErrorAction Stop
47+
}
48+
try {
49+
Add-Type -AssemblyName System.IO.Compression.FileSystem
50+
[System.IO.Compression.ZipFile]::ExtractToDirectory($ZipFilePath, $DownloadPath)
51+
}
52+
catch {
53+
Write-Host "Extracting with Shell.Application..." -ForegroundColor Yellow
54+
$Shell = New-Object -ComObject Shell.Application
55+
$Zip = $Shell.NameSpace($ZipFilePath)
56+
$Destination = $Shell.NameSpace($DownloadPath)
57+
$Destination.CopyHere($Zip.Items(), 4)
58+
}
59+
Write-Host "Files in extraction directory:" -ForegroundColor Yellow
60+
Get-ChildItem -Path $DownloadPath -Recurse | ForEach-Object {
61+
Write-Host $_.FullName -ForegroundColor Yellow
62+
}
63+
if (-Not (Test-Path -Path $Executable)) {
64+
throw "URL Disabler executable not found at $ExtractPath"
65+
}
66+
Write-Verbose -Message "URL Disabler executable located at: $($Executable)"
67+
if ($StartApplication) {
68+
Write-Host "Starting URL Disabler..." -ForegroundColor Green
69+
Start-Process -FilePath $Executable -Wait
70+
}
71+
}
72+
catch {
73+
Write-Error -Message "An error occurred: $_"
74+
}
75+
finally {
76+
Write-Host "URL Disabler operation completed." -ForegroundColor Cyan
77+
if ($RemoveFiles) {
78+
Write-Warning -Message "Cleaning up, removing the temporary folder..."
79+
Remove-Item -Path $DownloadPath -Force -Recurse -Verbose
80+
}
81+
}
82+
}

0 commit comments

Comments
 (0)