我必须运行PowerShell脚本,这需要很长时间才能完成。
在此期间,我想阻止运行它的计算机被用户关闭。
有办法做到这一点吗?
答案 0 :(得分:0)
这样的事可能有用(未经测试):
$File = "$env:SystemRoot\system32\shutdown.exe"
$PreviousAcl = Get-Acl $File
$Principal = "domain\user"
$Right = "Read"
$Rule = New-Object System.Security.AccessControl.FileSystemAccessRule($Principal,$Right,"Deny")
Try {
$Acl = Get-Acl $File
$Acl.SetAccessRule($Rule)
Set-Acl $File $Acl
}
Catch {
Write-Error "ACL failed to be set on: " $File
}
# yourscript here
Try {
Set-Acl $File $PreviousAcl
}
Catch {
Write-Error "ACL failed to be set on: " $File
}