无需挂起程序即可更改网络连接

无需挂起程序即可更改网络连接

我在远程计算机上运行一个程序,如果我通过在适配器属性中指定另一个网关和 DNS 地址来更改网络,该程序将照常工作,不会出现任何问题。

但是,当我从命令行进行网络切换时,如下所示:

netsh int ip set address "Local Area Connection" static 169.254.144.10 255.255.255.0 169.254.144.200 1
netsh int ip set dns "Local Area Connection" static 169.254.144.200 primary validate=no

它会使程序在 Windows 8 上挂起,在 Windows 7 上它将正常工作,直到您尝试退出窗口,只有那时它才会说它没有响应。

我尝试转储配置并恢复它(netsh interface dumpnetsh exec dumpfile.dat),但我无法测试这种方法,因为在转储文件中没有提到网关或 DNS——不知道为什么它没有包含在那里,因为那是必不可少的……

在更多计算机上测试了此行为。在我看来,通过命令进行更改似乎更及时,因为当我使用上述命令运行脚本时,我可以看到任务栏上的一些在线相关图标断开连接然后重新连接。当我手动切换时,它们甚至不会闪烁。我猜驱动器映射会暂时断开连接,这就是程序挂起的原因……

那么手动更改网络和使用 netsh 命令有什么区别?如何从命令更改为以相同方式实现切换?


该程序具有文本用户界面,在命令窗口中打开。它必须从映射驱动器运行,因为 cmd 不支持 UNC 路径。

挂起时的详细信息:

Problem signature:
  Problem Event Name:   InPageError
  Error Status Code:    c000020c
  Faulting Media Type:  00000000
  OS Version:   6.1.7601.2.1.0.256.48
  Locale ID:    1048
  Additional Information 1: 9189
  Additional Information 2: 9189fca27356e4825c153d6761541c45
  Additional Information 3: 5c2b
  Additional Information 4: 5c2b4817a0e33e756d6f79da7728e015

远程计算机是 Windows 2008 服务器,但我在本地运行该程序。

我的转储文件:

#========================
# Interface configuration
#========================
pushd interface 


popd
# End of interface configuration



# ----------------------------------
# IPHTTPS Configuration
# ----------------------------------
pushd interface httpstunnel

reset


popd
# End of IPHTTPS configuration



# ----------------------------------
# IPv4 Configuration
# ----------------------------------
pushd interface ipv4

reset
set global icmpredirects=enabled
add route prefix=0.0.0.0/0 interface="Local Area Connection" nexthop=169.254.144.200 metric=1 publish=Yes
add address name="VirtualBox Host-Only Network" address=192.168.56.1 mask=255.255.255.0
add address name="VMware Network Adapter VMnet1" address=192.168.6.1 mask=255.255.255.0
add address name="VMware Network Adapter VMnet8" address=192.168.111.1 mask=255.255.255.0
add address name="Local Area Connection" address=169.254.144.155 mask=255.255.255.0


popd
# End of IPv4 configuration



# ----------------------------------
# IPv6 Configuration
# ----------------------------------
pushd interface ipv6

reset
set interface interface="Teredo Tunneling Pseudo-Interface" forwarding=disabled advertise=disabled mtu=1280 metric=0 siteprefixlength=0 nud=disabled routerdiscovery=disabled managedaddress=disabled otherstateful=disabled weakhostsend=disabled weakhostreceive=disabled ignoredefaultroutes=disabled advertisedrouterlifetime=0 advertisedefaultroute=disabled currenthoplimit=0 forcearpndwolpattern=disabled enabledirectedmacwolpattern=disabled


popd
# End of IPv6 configuration



# ----------------------------------
# ISATAP Configuration
# ----------------------------------
pushd interface isatap



popd
# End of ISATAP configuration



# ----------------------------------
# 6to4 Configuration
# ----------------------------------
pushd interface 6to4

reset



popd
# End of 6to4 configuration



# ----------------------------------
# ISATAP Configuration
# ----------------------------------
pushd interface isatap



popd
# End of ISATAP configuration


#========================
# Port Proxy configuration
#========================
pushd interface portproxy

reset


popd

# End of Port Proxy configuration



# ----------------------------------
# TCP Configuration
# ----------------------------------
pushd interface tcp

reset

set global rss=enabled chimney=automatic autotuninglevel=normal congestionprovider=none ecncapability=disabled timestamps=disabled netdma=enabled dca=enabled

Dump has failed when retreiving chimneyapplication  settings.

Dump has failed when retreiving chimneyapplication  settings.

Dump has failed when retreiving chimneyapplication  settings.

Dump has failed when retreiving chimneyapplication  settings.


popd
# End of TCP configuration



# ----------------------------------
# Teredo Configuration
# ----------------------------------
pushd interface teredo
set state type=client servername=teredo.ipv6.microsoft.com. servervirtualip=0.0.0.0



popd
# End of Teredo configuration



# ----------------------------------
# 6to4 Configuration
# ----------------------------------
pushd interface 6to4

reset



popd
# End of 6to4 configuration

相关内容