bat批处理命令以管理员权限执⾏powershell命令
写⼀个bat脚本,两个功能:
1.有两个⽹卡,启⽤⼀个⽹卡并禁⽤另⼀个⽹卡
2.启⽤的⽹卡提升优先级,禁⽤的就降低优先级
启⽤⽹卡
netsh interface set interface “以太⽹” enabled
禁⽤⽹卡
netsh interface set interface “以太⽹” disabled
powershell怎么以管理员身份运行设置⽹卡优先级,InterfaceMetric 为跃点数,跃点数越⼩优先级越⾼。不过呢这不是cmd命令,属于powershell命令,必须在powershell上运⾏⽽且还要管理员权限。
Set-NetIPInterface -InterfaceAlias 以太⽹ -InterfaceMetric 10
所以就要改变⼀下写法,不能直接在cmd中运⾏
powershell -noprofile -command “&{ start-process powershell -ArgumentList ‘Set-NetIPInterface -InterfaceAlias 以太⽹ -InterfaceMetric 10’ -verb RunAs}”
这样可以成功修改⽹卡跃点数。
可以⽤Get-NetIPInterface查看
测试环境win10。