无法以管理员身份运行PowerShell

时间:2015-05-27 12:58:09

标签: powershell

我试图在Windows Server 2012 r2上以管理员身份运行powershell脚本。问题是,只要我以管理员身份启动脚本,就会关闭并运行它。如果我启动PowerShell ISE并从那里以管理员身份运行脚本,该脚本将起作用。我缺少一个设置吗?

2 个答案:

答案 0 :(得分:0)

可能禁用了脚本执行。首先尝试运行它。

set-executionpolicy -unrestricted

答案 1 :(得分:0)

我将Windows Server 2012上的cmd设置为始终以管理员身份运行:

REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "c:\Windows\System32\cmd.exe" /t REG_SZ /d "RUNASADMIN" /f
REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "c:\Windows\SysWOW64\cmd.exe" /t REG_SZ /d "RUNASADMIN" /f
REG ADD "HKU\.DEFAULT\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "c:\Windows\System32\cmd.exe" /t REG_SZ /d "RUNASADMIN" /f
REG ADD "HKU\.DEFAULT\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "c:\Windows\SysWOW64\cmd.exe" /t REG_SZ /d "RUNASADMIN" /f
REG ADD "HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "c:\Windows\System32\cmd.exe" /t REG_SZ /d "RUNASADMIN" /f
REG ADD "HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "c:\Windows\SysWOW64\cmd.exe" /t REG_SZ /d "RUNASADMIN" /f

也许它也适用于PowerShell。

相关问题