2

我对powershell很陌生,我不确定我做错了什么。它在我的 Windows 8 PC 上运行良好,但是当我将它发送给其他人时(他有 Windows 7;为他创建了这个),他得到一个不允许运行脚本的错误。

尝试使用 -ExecutionPolicy RemoteSigned 但仍然没有运气。

##################
<# CONFIG START #>
##################
#replace the path with your steam path. For example: C:\Program Files (x86)\Steam\Steam.exe
$steam_path = "C:\Program Files (x86)\Steam\steam.exe"

#You can change it to Ethernet 1 or Ethernet 2 or Ethernet 3 etc depending on which adapter you want to disable.
#If you have custom name for them (you can rename them from control panel), have to use that name.
$adapter_name = "Ethernet 1"

<#
What program to run.
1: Steam Dota 2
2: Steam CS
3: Steam CSS
4: Steam CSGO
5: Custom Program 1
6: Custom Program 2
7: Custom Program 3
#>
$game_id = "5"

<# Custom Program path and arguments#>
$cp1_path = "C:\Program Files (x86)\counter-strike source\css.exe"
$cp1_arg = " "

$cp2_path = ""
$cp2_arg = " "

$cp3_path = ""
$cp2_arg = " "

$delay = 20


################
<# CONFIG END #>
################


"Checking admin permissions..."

If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{
    "Administrator permissions required."
    $arguments = '-ExecutionPolicy RemoteSigned -file "' + $myinvocation.mycommand.definition + '"'
#    $arguments
    Start-Process powershell -Verb runAs -ArgumentList $arguments
    Break
}


"Exiting Steam..."
Start-Process -FilePath $steam_path -ArgumentList "-shutdown" -Wait:$true

Start-Sleep -s 2

"Disabling Network Adapter..."
Disable-NetAdapter -Name $adapter_name -Confirm:$false

Start-Sleep -s 5

"Starting Game..."

Switch($game_id)
{

    1
    {
        Start-Process -filepath "steam://rungameid/570"
    }

    2
    {
        Start-Process -filepath "steam://rungameid/10"
    }

    3
    {
        Start-Process -filepath "steam://rungameid/240"
    }

    4
    {
        Start-Process -filepath "steam://rungameid/730"
    }

    5
    {
        Start-Process $cp1_path -ArgumentList $cp1_arg
    }

    6
    {
        Start-Process $cp2_path -ArgumentList $cp2_arg
    }

    7
    {
        Start-Process $cp3_path -ArgumentList $cp3_arg
    }
}

Start-Sleep -s $delay

"Enabling Network Adapter..."
Enable-NetAdapter $adapter_name -Confirm:$false

exit
4

2 回答 2

3

如果你把剧本发给他,那就RemoteSigned很好了。他从远程(从您那里)获得了脚本,并且没有签名,因此不会执行。

告诉您的朋友在 Windows 资源管理器中导航到ps1脚本并右键单击,然后选择“取消阻止”。如果 PowerShell 实例已经无法运行脚本,他将需要重新启动该实例,因为此类信息已被 Windows 缓存。

于 2013-06-02T22:55:00.660 回答
0

该错误表明您没有正确设置执行策略。首先,您以管理员身份运行 Powershell。为此,请右键单击开始菜单中的 Powershell 图标,然后单击“以管理员身份运行”。接下来,您必须在 Powershell 中运行以下命令:

Set-ExecutionPolicy RemoteSigned

系统将提示您允许更改。键入“Y”并按回车键。

最后,尝试运行您的脚本。

于 2013-06-02T22:53:30.110 回答