remove-autostart
This commit is contained in:
1 parent
2d80538377
commit
e7ed05922e
3 files changed
+89
No files matched your search
@@ -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:
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
@echo off
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0remove-autostart.ps1"
|
||||
echo.
|
||||
pause
|
||||
@@ -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."
|
||||
Reference in new issue
Block a user