我对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
答案 0 :(得分:3)
如果你给他发了剧本,那么RemoteSigned
正在做好它的工作。他远程(从你那里)获得了脚本并且没有签名,所以它不会被执行。
告诉您的朋友在Windows资源管理器中导航到ps1
脚本并右键单击,然后选择“取消阻止”。然后,如果它已经无法运行脚本,则需要重新启动PowerShell实例,因为Windows会缓存此类信息。
答案 1 :(得分:0)
错误表示您未正确设置执行策略。首先,您以管理员身份运行Powershell。要执行此操作,请右键单击开始菜单中的Powershell图标,然后单击“以管理员身份运行”。接下来,您必须在Powershell中运行以下命令:
Set-ExecutionPolicy RemoteSigned
系统将提示您允许更改。输入“Y”并按回车。
最后,尝试运行您的脚本。