首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过具有管理权限的启动进程启动时,延迟关闭PowerShell窗口

通过具有管理权限的启动进程启动时,延迟关闭PowerShell窗口
EN

Stack Overflow用户
提问于 2012-11-10 15:03:07
回答 1查看 513关注 0票数 1

代码(不是我的实际代码,但也会产生相同的行为):

代码语言:javascript
复制
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位.

EN

回答 1

Stack Overflow用户

发布于 2013-01-13 05:49:08

这是一个Read-Host问题。它并不只影响64位操作系统,我只是在x86和x64 Windows7Pro上进行了验证。要进行复制,只需在任何Read-Host控制台上运行PowerShell并关闭窗口。

更新:

我刚刚在不同版本的Windows和bit-ness上进行了测试,我发现结果并不一致。Read-Host的行为似乎有些不同,有时是不同的运行方式。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13323157

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档