【发布时间】:2021-03-27 20:30:49
【问题描述】:
我编写了一个 PowerShell 脚本来授予运行权限以在没有管理员权限的情况下运行。所以我需要从批处理文件中运行该脚本。在这里,我附上了我的 PowerShell 脚本和批处理文件。我无法从我的批处理文件运行 PowerShell 脚本。
Access.ps1
powershell -File "%~dpn0.ps1" %*
Start-Process PowerShell -ArgumentList "Set-ExecutionPolicy Unrestricted -Force" -Verb RunAs
$key = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey("SOFTWARE\Wow6432Node\Unicorn",[Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree,[System.Security.AccessControl.RegistryRights]::ChangePermissions)
$acl = $key.GetAccessControl()
$rule = New-Object System.Security.AccessControl.RegistryAccessRule (".\USERS","FullControl",@("ObjectInherit","ContainerInherit"),"None","Allow")
$acl.SetAccessRule($rule)
$key.SetAccessControl($acl)
Write-Host "Successfully set permission to PM Registry!"
Access.bat
@ECHO OFF
PowerShell.exe -Command "& '%~dpn0.ps1'"
PAUSE
这是错误
【问题讨论】:
-
Access.ps1真的以powershell -File "%~dpn0.ps1" %*开头,还是复制粘贴错误?如果是错误,请edit问题。还有,会发生什么?有错误信息吗?没有?输出错误? -
@vonPryz 更新错误
标签: powershell batch-file