我只发现了一种实际需要这样做的情况,就像 Gary 提到的那样,我将其包装在一些逻辑中以避免滚动连续重启。
我们遇到了这样一种情况,即“新创建的”服务器有一些挂起的文件重命名,即使多次重启也不会真正消失,所以如果我们运行 Boxstarter,如果我们可以在两者之间登录,我们最终不得不尽快终止 cmd 窗口无限重启。
生成的脚本可以从 gist via 运行Install-BoxstarterPackage -DisableReboots <gistUrl>
以清理您放入 $badFile 的任何文件(您可以制作一个列表)。
此脚本的一个警告是它需要交互式提示登录凭据。如果您信任您的系统和网络,您可以使用纯文本密码并组装一个凭证,我认为这是最坏的情况。
抱歉,这似乎破坏了语法荧光笔。
Import-Module $env:appdata\Boxstarter\Boxstarter.Common
$badSpoolReg = '\??\C:\Windows\system32\spool\PRTPROCS\x64\1_hpcpp130.dll'
$badSpoolFile = 'C:\Windows\system32\spool\PRTPROCS\x64\1_hpcpp130.dll'
# Next bits taken from the 'Get-PendingReboot' module on the Script Gallery.
$Computer = $env:COMPUTERNAME
$HKLM = [UInt32] "0x80000002"
$WMI_Reg = [WMIClass] "\\$Computer\root\default:StdRegProv"
## Query PendingFileRenameOperations from the registry
$RegSubKeySM = $WMI_Reg.GetMultiStringValue($HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager\","PendingFileRenameOperations")
#$RegSubKeySM # Debug print of the list if you want to run by hand
$RegValuePFRO = $RegSubKeySM.sValue | where { $_ } # Ignore empty values
#$RegValuePFRO # Debug print of the list if you want to run by hand
# Credential is required for Create-BoxstarterTask
# Create-BoxstarterTask required to call Invoke-FromTask
# see https://github.com/mwrock/boxstarter/issues/121
$cred = Get-Credential
Create-BoxstarterTask $cred
# Perhaps could be improved using set membership comparison?
# like (if $badSpoolReg in $RegValuePFRO.Values?)
foreach ($path in $RegValuePFRO) {
if ($path -contains $badSpoolReg) {
write-output "Bogey on my six!"
Get-Service spooler | stop-service
Invoke-FromTask "rm -fo $badSpoolFile" # Files in "protected" paths require extra work to remove
$Boxstarter.RebootOk = $true # Need to enable this to allow Invoke-Reboot to work
Write-output "Took out the bogey, resetting system state"
Invoke-Reboot # Manually called but within a fairly good gate
} else {
write-output "No bogeys sighted Captain!"
}
}
Remove-BoxstarterTask