此脚本重新启动Taskmanager并在其窗口中显示更多详细信息,并在Windows 10上运行
If (!(Test-Path HKCU:\Software\Microsoft\Windows\CurrentVersion\TaskManager))
{
New-Item -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\TaskManager -Force
}
$preferences = Get-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\TaskManager -Name Preferences -ErrorAction SilentlyContinue
If (!($preferences))
{
$taskmgr = Get-Process Taskmgr -ErrorAction SilentlyContinue
If ($taskmgr)
{
$taskmgr | Stop-Process -Force
}
Start-Process -FilePath Taskmgr
}
$preferences = Get-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\TaskManager -Name Preferences -ErrorAction SilentlyContinue
$preferences.Preferences[28] = 0
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\TaskManager -Name Preferences -Type Binary -Value $preferences.Preferences -Force
If ($taskmgr)
{
$taskmgr | Stop-Process -Force
}
Start-Process -FilePath Taskmgr
但在Windows 8.1上遇到错误
Unable to index in array NULL
+ $preferences.Preferences[28] = 0
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
答案 0 :(得分:0)
一些建议:
如果删除ErrorAction,在这种情况下可能会出现异常,这可能表明该路径不存在。或者,$ Preferences.Preferences在数组中没有28个项目。
/帕特里克
答案 1 :(得分:0)
我可以证明使用Stop-Process
强制杀死任务管理器 强制不会创建Preferences
注册表值(正在运行Windows 8.1/64
)。
创建Preferences
注册表值需要常规完成 任务管理器,即用户的合作(请参阅以下脚本中的$taskmgr | Wait-Process
)。
$taskmgrPath = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\TaskManager'
If (!(Test-Path $taskmgrPath))
{
New-Item -Path $taskmgrPath -Force
}
$taskmgr = Get-Process Taskmgr -ErrorAction SilentlyContinue
If ($taskmgr)
{
#$taskmgr | Stop-Process -Force
$taskmgr | Wait-Process
}
$preferences = Get-ItemProperty -Path $taskmgrPath -Name Preferences -ErrorAction SilentlyContinue
If (!($preferences))
{
Start-Process -FilePath Taskmgr
$taskmgr = Get-Process Taskmgr -ErrorAction SilentlyContinue
If ($taskmgr)
{
#$taskmgr | Stop-Process -Force
$taskmgr | Wait-Process
}
$preferences = Get-ItemProperty -Path $taskmgrPath -Name Preferences -ErrorAction SilentlyContinue
}
$preferences.Preferences[28] = 0
New-ItemProperty -Path $taskmgrPath -Name Preferences -Type Binary -Value $preferences.Preferences -Force
If ($taskmgr)
{
$taskmgr | Stop-Process -Force
}
Start-Process -FilePath Taskmgr ## restart Task manager with modified properties
或者,将 Alt + F4 发送到任务管理器。窗口,即两个方面的'%{F4}'
字符串
.Sendkeys()
COM对象WScript.Shell
的方法,或::SendWait()
.NET类的静态方法[System.Windows.Forms.SendKeys]
答案 2 :(得分:0)
$taskmgr = Get-Process Taskmgr -ErrorAction SilentlyContinue
If ($taskmgr)
{
$taskmgr.CloseMainWindow()
}
Start-Process -FilePath Taskmgr
Start-Sleep -Seconds 1
$taskmgr = Get-Process Taskmgr -ErrorAction SilentlyContinue
If ($taskmgr)
{
$taskmgr.CloseMainWindow()
}
Start-Sleep -Seconds 1
$preferences = Get-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\TaskManager -Name Preferences
$preferences.Preferences[28] = 0
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\TaskManager -Name Preferences -Type Binary -Value $preferences.Preferences -Force
Start-Process -FilePath Taskmgr