求帮助:怎么 vbs 使命令立即生效?谢谢

C++语言 码拜 7年前 (2017-04-12) 848次浏览
讨教:
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:\” & strComputer & “\root\cimv2”)
Set colNetAdapters = objWMIService.ExecQuery _
(“Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE”)
strIPAddress = Array(“192.168.0.141”)
strSubnetMask = Array(“255.255.255.0”)
strGateway = Array(“192.168.0.1”)
strGatewayMetric = Array(1)
For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
Next
这一段设置 IP 地址的 vbs 代码
运行后,
IP 地址是改变为
“192.168.0.141”
“255.255.255.0”
“192.168.0.1”
但是要重新计算机
程序才能使用它(可能是配置还没有起作用)
怎么使 不需要重起计算机,就可以 使用
这段代码 需要 怎么改?
谢谢!
解决方案

40

仅供参考:
setip.bat:

if "%1"=="l" goto l
if "%1"=="w" goto w
echo 网络地址切换批处理
echo    setip l     ——切换到本地连接
echo    setip w     ——切换到无线网络连接
goto e
:l
echo 从无线网络的静态ip切换到有线网络的静态ip:
netsh interface ip set address 无线网络连接 dhcp
netsh interface ip set dns 无线网络连接 dhcp
netsh interface ip set address 本地连接 static 192.168.1.111 255.255.252.0 192.168.2.1 1
netsh interface ip set dns 本地连接 static 202.106.196.115
goto e
:w
echo 从有线网络的静态ip切换到无限网络的静态ip:
netsh interface ip set address 本地连接 dhcp
netsh interface ip set dns 本地连接 dhcp
netsh interface ip set address 无线网络连接 static 192.168.1.5 255.255.255.0 192.168.1.1 1
netsh interface ip set dns 无线网络连接 static 211.97.168.129
goto e
:e

10

引用:

谢谢,
这段代码 需要 重新 启动计算机 才生效不?

不要迷信书、考题、老师、回帖;
要迷信CPU、编译器、调试器、运行结果。
并请结合“盲人摸太阳”和“驾船出海时一定只带一个指南针。”加以理解。
任何理论、权威、传说、真理、标准、解释、想象、知识……都比不上摆在眼前的事实!


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明求帮助:怎么 vbs 使命令立即生效?谢谢
喜欢 (0)
[1034331897@qq.com]
分享 (0)