以非管理员用户身份使用管理员运行 PowerShell

问题描述 投票:0回答:1

我尝试在学校笔记本电脑上以管理员身份运行 PowerShell。由于某种原因,我尝试运行的应用程序只能在 USB 驱动器上运行,因此,我想创建一个虚拟磁盘,让计算机认为它位于驱动器中。但不确定它是否会起作用,因为我对 PowerShell 之类的语言缺乏经验。

计算机无法访问 cmd,或者实际上任何其他可能能够为我提供某种管理功能的东西(任务管理器、gpedit 等)。

我在网上搜索过,但找不到避免 UAC 的方法。

我发现有些应用程序可能能够绕过 UAC,但不确定它们是什么。

我只需要绕过 PowerShell 的 UAC,同时将我的帐户保留为非管理帐户,或者以另一种方式运行前面提到的应用程序。

由于除了一些基本命令之外,我对 .bat 和 .ps1 语言了解不多,所以我不确定除了在 PowerShell 中使用

Set-ExecutionPolicy unrestricted -Scope CurrentUser
或在 .bat 文件中使用
set __COMPAT_LAYER=RunAsInvoker
之外,我还能尝试什么.

我还尝试过使用一个驱动器或网络驱动器之类的东西。

windows powershell uac
1个回答
0
投票
$currentPid = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$principal = new-object System.Security.Principal.WindowsPrincipal($currentPid)
$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator

if ($principal.IsInRole($adminRole))
{
   $Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Admin)"
   clear-host
}
else
{
   $newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell";
   $newProcess.Arguments = $myInvocation.MyCommand.Definition;
   $newProcess.Verb = "runas";
   [System.Diagnostics.Process]::Start($newProcess);
   break
}
© www.soinside.com 2019 - 2024. All rights reserved.