我正在寻找使用 PowerShell 禁用启动程序列表。我已经走了这么远,但后来碰壁了。目前,我无法获得第二个启动程序列表,以便像我的第一个一样很好地列出。
function Disable-Startups {
[CmdletBinding()]
Param(
[parameter(DontShow = $true)]
$32bit = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run",
[parameter(DontShow = $true)]
$32bitRunOnce = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce",
[parameter(DontShow = $true)]
$64bit = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run",
[parameter(DontShow = $true)]
$64bitRunOnce = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\RunOnce",
[parameter(DontShow = $true)]
$currentLOU = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run",
[parameter(DontShow = $true)]
$currentLOURunOnce = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce"
)
Begin {
$disableList = @(
"iTunesHelper",
"Cisco AnyConnect Secure Mobility Agent for Windows",
"Ccleaner Monitoring",
#"SunJavaUpdateSched",
"Steam",
"Discord"
)
New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS | Out-Null
$startups = Get-CimInstance Win32_StartupCommand | Select-Object Name,Location
}
Process {
foreach ($startUp in $startUps){
if ($startUp.Name -in $disableList){
$number = ($startUp.Location).IndexOf("\")
$location = ($startUp.Location).Insert("$number",":")
Write-Output "Disabling $($startUp.Name) from $location)"
#Remove-ItemProperty -Path "$location" -Name "$($startUp.name)"
}
}
$regStartList = Get-ItemProperty -Path $32bit,$32bitRunOnce,$64bit,$64bitRunOnce,$currentLOU,$currentLOURunOnce | Format-List
}
End {}
}
所以基本上当$regStartList
开始时,我想要每个注册表的每个项目的显示名称和位置,并且我想将所有这些放入一个变量中。但我无法列出这样的好清单
名称 位置 ---- -------- OneDriveSetup HKU\S-1-5-19\SOFTWARE\Microsoft\Windows\CurrentVersion\Run OneDriveSetup HKU\S-1-5-20\SOFTWARE\Microsoft\Windows\CurrentVersion\Run 发送到 OneNote 启动 OneDrive HKU\S-1-5-21-3687383513-804626811-2257261628-1001\SOFTWARE\Microsoft\Windows\CurrentVersion\Run CCleaner 监控 HKU\S-1-5-21-3687383513-804626811-2257261628-1001\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
但是得到这个,即使我跑了。
$regStartList = Get-ItemProperty -Path $32bit,$32bitRunOnce,$64bit,$64bitRunOnce,$currentLOU,$currentLOURunOnce | Select-Object name,location
name location
---- --------
出于某种原因,没有获取位置或名称/显示名称。
编辑:我回答了我自己的问题,但如果有人有更好的问题,请告诉我。
$regStartList = Get-Item -path $32bit,$32bitRunOnce,$64bit,$64bitRunOnce,$currentLOU,$currentLOURunOnce |
Where-Object {$_.ValueCount -ne 0} | Select-Object property,name
foreach ($regName in $regStartList.name) {
$regNumber = ($regName).IndexOf("\")
$regLocation = ($regName).Insert("$regNumber",":")
if ($regLocation -like "*HKEY_LOCAL_MACHINE*"){
$regLocation = $regLocation.Replace("HKEY_LOCAL_MACHINE","HKLM")
write-host $regLocation
}
if ($regLocation -like "*HKEY_CURRENT_USER*"){
$regLocation = $regLocation.Replace("HKEY_CURRENT_USER","HKCU")
write-host $regLocation
}
foreach($disable in $disableList) {
if (Get-ItemProperty -Path "$reglocation" -name "$Disable"-ErrorAction SilentlyContinue) {
Write-host "yeah i exist"
#Remove-ItemProperty -Path "$location" -Name "$($startUp.name)" -whatif
}else {write-host "no exist"}
}
}