代码(不是我的实际代码,但也会产生相同的行为):
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
[Security.Principal.WindowsBuiltInRole] "Administrator"))
{
Write-Warning "The script tries to re-run itself using Administrator privileges.";
try {
Start-Process powershell -ArgumentList ($MyInvocation.MyCommand.Path) -Verb runAs;
}
catch [InvalidOperationException] {
Write-Warning "You canceled the privilege request. This script WON'T WORK, please re-run it!";
Read-Host;
Exit;
}
Exit;
}
# Here comes the code which will be run if started with Admin rights
Read-Host;当我接受Windows并通过[X]关闭出现的PS窗口时,窗口将在3-5秒内消失,而不是直接关闭!
我使用的是Windows 8 Pro 64位.
发布于 2013-01-13 05:49:08
这是一个Read-Host问题。它并不只影响64位操作系统,我只是在x86和x64 Windows7Pro上进行了验证。要进行复制,只需在任何Read-Host控制台上运行PowerShell并关闭窗口。
更新:
我刚刚在不同版本的Windows和bit-ness上进行了测试,我发现结果并不一致。Read-Host的行为似乎有些不同,有时是不同的运行方式。
https://stackoverflow.com/questions/13323157
复制相似问题