From e7ed05922e1a146e1e0420c6a84c526615ad0279 Mon Sep 17 00:00:00 2001 From: R0GGER Date: Sat, 7 Nov 2026 12:41:54 +0100 Subject: [PATCH] remove-autostart --- README.md | 10 +++++ tools/remove-autostart.cmd | 4 ++ tools/remove-autostart.ps1 | 75 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 tools/remove-autostart.cmd create mode 100644 tools/remove-autostart.ps1 diff --git a/README.md b/README.md index 439ee37..02c5172 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,16 @@ Een losse .NET-installatie is niet nodig; de installer bevat alles wat kniip nod Verwijder kniip via **Instellingen > Apps > Geïnstalleerde apps**. Autostart en de 'Openen met'-registratie worden daarbij ook opgeruimd. +Heb je alleen `Kniip.exe` gestart en geen installer gebruikt, dan staat kniip mogelijk nog bij **Instellingen > Apps > Opstarten**. Die regel wijst naar de map waar de exe toen stond. De schakelaar daar uitzetten verbergt kniip niet: Windows bewaart de regel en zet hem alleen op uit. + +`tools\remove-autostart.cmd` haalt de regel weg. Dubbelklik het bestand, of voer uit: + +```powershell +powershell -NoProfile -ExecutionPolicy Bypass -File .\tools\remove-autostart.ps1 +``` + +Het script geldt voor de aangemelde gebruiker. Het pad van de exe maakt niet uit en het bestand hoeft er niet meer te staan. Beheerdersrechten zijn niet nodig. Elke Windows-account heeft een eigen opstartlijst, dus draai het in de account waarin kniip een keer is gestart. Blijft de vermelding daarna zichtbaar, log dan een keer uit en weer in. + ## Zelf bouwen Vereisten: diff --git a/tools/remove-autostart.cmd b/tools/remove-autostart.cmd new file mode 100644 index 0000000..24883be --- /dev/null +++ b/tools/remove-autostart.cmd @@ -0,0 +1,4 @@ +@echo off +powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0remove-autostart.ps1" +echo. +pause diff --git a/tools/remove-autostart.ps1 b/tools/remove-autostart.ps1 new file mode 100644 index 0000000..53e3c47 --- /dev/null +++ b/tools/remove-autostart.ps1 @@ -0,0 +1,75 @@ +# Haalt kniip uit Windows Opstart-apps voor de aangemelde gebruiker. +# Bedoeld voor wie alleen Kniip.exe heeft gedraaid (geen installer): het pad van de exe +# maakt niet uit, en het bestand hoeft er niet meer te staan. +# +# Elke Windows-account heeft een eigen opstartlijst. Draai dit script in de account +# waarin kniip een keer is gestart. Beheerdersrechten zijn niet nodig. +# +# powershell -NoProfile -ExecutionPolicy Bypass -File .\tools\remove-autostart.ps1 +# of dubbelklik op remove-autostart.cmd + +$ErrorActionPreference = "Stop" + +$knownNames = @("Kniip", "KnipPlus") +$exePattern = '(?i)(^|[\\/"])(Kniip|KnipPlus)\.exe(\b|")' + +function Test-KniipCommand([string]$text) { + return [bool]($text -match $exePattern) +} + +function Remove-NamedValue([string]$keyPath, [string]$name) { + if (-not (Test-Path -LiteralPath $keyPath)) { return $false } + $key = Get-Item -LiteralPath $keyPath + if ($key.GetValueNames() -notcontains $name) { return $false } + Remove-ItemProperty -LiteralPath $keyPath -Name $name + return $true +} + +$removed = New-Object System.Collections.Generic.List[string] +$runKey = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run" +$approvedRunKey = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run" +$names = New-Object System.Collections.Generic.HashSet[string] + +foreach ($name in $knownNames) { [void]$names.Add($name) } + +if (Test-Path -LiteralPath $runKey) { + $run = Get-Item -LiteralPath $runKey + foreach ($name in @($run.GetValueNames())) { + $data = [string]$run.GetValue($name) + if ($names.Contains($name) -or (Test-KniipCommand $data)) { + Remove-ItemProperty -LiteralPath $runKey -Name $name + $removed.Add("Run\$name ($data)") + [void]$names.Add($name) + } + } +} + +foreach ($name in $names) { + if (Remove-NamedValue $approvedRunKey $name) { + $removed.Add("StartupApproved\Run\$name") + } +} + +$startup = [Environment]::GetFolderPath("Startup") +$approvedStartupKey = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\StartupFolder" +$wsh = New-Object -ComObject WScript.Shell +Get-ChildItem -LiteralPath $startup -Filter "*.lnk" -ErrorAction SilentlyContinue | ForEach-Object { + $shortcut = $wsh.CreateShortcut($_.FullName) + $hit = (Test-KniipCommand $shortcut.TargetPath) -or (Test-KniipCommand $shortcut.Arguments) -or ($knownNames -contains $_.BaseName) + if (-not $hit) { return } + Remove-Item -LiteralPath $_.FullName -Force + $removed.Add("Opstartmap\$($_.Name)") + if (Remove-NamedValue $approvedStartupKey $_.Name) { + $removed.Add("StartupApproved\StartupFolder\$($_.Name)") + } +} + +if ($removed.Count -eq 0) { + Write-Host "Geen kniip-opstartregistratie gevonden voor $env:USERNAME." + exit 0 +} + +Write-Host "Verwijderd voor ${env:USERNAME}:" +foreach ($line in $removed) { Write-Host " $line" } +Write-Host "" +Write-Host "kniip staat niet meer in Opstart-apps. Staat de regel er nog, log dan een keer uit en weer in."