wes7首次连接网络后,弹出设置网络位置对话框

定制的wes7操作系统,启动后首次连入网络,会出现如下对话框。怎样默认设置选择一个默认的网络位置呢?

解决方法:

执行powershell脚本setnetworklocation.ps1 ,即可将所有网络接口归为工作网络,脚本如下:

$networkListManager = [Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]"{DCB00C01-570F-4A9B-8D69-199FDBA5723B}"))
$connections = $networkListManager.GetNetworkConnections()
$connections | % {$_.GetNetwork().SetCategory(1)}

如果把最后一行里SetCategory(1)改成SetCategory(0)则是全归为公用网络。

为防止恶意脚本的执行,PowerShell有一个执行策略,默认情况下,这个执行策略被设为受限的(Restricted),这意味着PowerShell脚本无法执行,此时可以使用下面的cmdlet命令确定当前的执行策略:

Get-ExecutionPolicy 你可以选择使用的执行策略有:

Restricted - 脚本不能运行。 RemoteSigned - 本地创建的脚本可以运行,但从网上下载的脚本不能运行(除非它们拥有由受信任的发布者签署的数字签名)。 AllSigned – 仅当脚本由受信任的发布者签名才能运行。 Unrestricted – 脚本执行不受限制,不管来自哪里,也不管它们是否有签名。

可以用批处理设置权限,批处理内容如下:

@echo off 
:STR 
REG add hklm\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell /v ExecutionPolicy  /t REG_SZ  /d remotesigned  /F
for /f "delims=" %%a in ('REG QUERY hklm\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell /v ExecutionPolicy') do set test=%%a  
::从注册表中获得ExcutionPolicy的权限键值 
 
set test1=%test:~33% 
::截取最后值的内容 
 
echo %test1% | findstr "Restricted" >nul 2>nul 
if !errorlevel! equ 0 ( 
    echo 当前系统未开启PowerShell脚本,将修改注册表开启脚本支持 
    powershell set-executionpolicy remotesigned 
) else ( 
    echo %test1% | findstr "RemoteSigned" >nul 2>nul 
    if !errorlevel! equ 0 ( 
        echo 当前系统ExecutePolicy状态为: %test1% 
        echo 尝试强制设定为RemoteSigned 
        :powershell set-executionpolicy remotesigned 
       : pause 
        goto STR 
    ) else ( 
        echo 当前系统ExecutePolicy状态为: %test1% 
        echo 该状态已经开启本地脚本执行支持,开启PS脚本 
        goto SPS 
    ) 
 

 
:SPS 
powershell "D:\setnetworklocation.ps1" 

原文地址:https://www.cnblogs.com/binbinxiang/p/2876940.html