[原创]解决XP开机慢一例

症状 Problem:在Windows XP开机启动的过程中,登录用户之后,加载桌面时,系统会挂起(图标点不开、后台程序加载不完全,并且在“任务管理器”的进程列表中一般不显示用户名),一般在一、两分钟之后才继续加载,然后正常。During the boot-up progress, when the user’s desktop is being loaded after login, the operating system hangs up (any program is unable to launch, not all system services are loaded, and generally the "user-name" colomn in "task list" of "Task Manager" is remained blank). It will be one or two minutes before all things go back into order.

 

分析 Analysis:这是Windows XP臭名昭著的BUG之一,是由于网络连接的TCP/IP协议之DHCP协议引起的。病理为:系统在加载桌面时,同时启动网络连接,应用TCP/IP设置。如果任意一个配置为“启用”的网络连接配置了DHCP协议,那么将进行DHCP的过程。而我们不能保证在开机时DHCP服务器都存在(比如网线没有连接、无线网络尚未打开等等),那么无法进行的DHCP过程会进入超时等待。下面就是BUG:Windows XP的DHCP模块要等待服务器连接六十秒(或者是多长时间?)才确定为超时,而两次超时之后才会报告连接DHCP服务器失败;另一方面,操作系统要等待所有网络连接配置好之后才可以继续加载某些系统服务,而用户桌面等程序依赖这些系统服务,环环相扣,那么就变成系统挂起了。This problem is caused by a well-known program bug of Windows XP, located in the DHCP module, which is in TCP/IP protocol controlling the network connection for the system. The whole progress could be described as below: the XP system will activate network connections and apply TCP/IP settings when the user’s desktop is loading. If any one of the ‘activated’ connections has been set to use DHCP, the system will start a DHCP circle. However, we can’t assure that the DHCP servers are available when we boot up computer, as the net wire may not be connected correctly, wireless AP not configured properly, etc., so the DHCP circle will run into time-out progress (waiting for DHCP servers). Then the bug comes up: The DHCP module of Windows XP is set to wait for 60 seconds (or about) after which a time-out event is generated, and time-out must occur twice before the system recongnizes a failure; on the other side, the system must stop loading certain services and background tasks until the network connection is configured correctly, but the user’s desktop depends on those services – all linked with one another, therefore the system hangs up.

 

解决办法 Solution:通常来说,最简单的方法是关机之前禁用使用DHCP的网络连接(在“网络连接”中选择“禁用”),但这需要鼠标操作,我们认为凡是需要鼠标操作的东西都很麻烦,所以说简单的也有可能是麻烦的。以下方案,使用netsh命令,在关机前自动地将DHCP功能关闭,在开机登录后再自动地开启DHCP功能。Generally, the simplest way to solve this problem is to disable those network connections, which are configured to use DHCP (select "disable" in Network Connections panel), but this requires mouse-click. We suggest that all the operations that involve mouse-clicking action are troublesome – so sometimes simple is complicated. The following solution will give you an automatic mechanism, which uses Windows’ applet netsh.exe, to close down the DHCP function at system shut down, and re-activate it after system log on.

Step 1. 编写以下两个netsh脚本: compose the following netsh scripts.

setdhcp.txt

***

interface ip
set address name=无线网络连接 source=dhcp
rem set address name=本地连接 source=dhcp
rem set address name="VMware Network Adapter VMnet8" source=dhcp
rem set address name="VMware Network Adapter VMnet1" source=dhcp
rem set address name="1394 连接" source=dhcp
bye

***

disabledhcp.txt

***

interface ip
set address name=无线网络连接 source=static addr=192.168.10.31 mask=255.255.255.0
rem set address name=本地连接 source=static addr=172.10.20.1 mask=255.255.255.0
rem set address name="VMware Network Adapter VMnet8" source=static addr=172.10.20.1 mask=255.255.255.0
rem set address name="VMware Network Adapter VMnet1" source=static addr=172.10.20.1 mask=255.255.255.0
rem set address name="1394 连接" source=static addr=172.10.20.1 mask=255.255.255.0
bye

***

说明 Note:利用interface ip功能更改网络连接之TCP/IP协议的配置。其中可能需要使用者自行更改的字段包括:(1) name=无线网络连接  例:在“网络连接”中,存在一个连接,显示名称为“Local Area Connection”,那么,就将该字段更改为 name="Local Area Connection"。(2) addr和mask字段分别对应手工配置的IP地址和子网掩码,(3) source字段定义是使用DHCP还是手工配置。 rem不是netsh的命令,执行时会报错,但是可以用来当作注释行的标记。Function interface ip is developed to adjust TCP/IP configurations of network connections. These fields may have to be modified by user: a) name=无线网络连接 e.g. If there is a connection with name displayed as "Local Area Connection", then this field should be written as name="Local Area Connection". b) Field addr and mask refers to IP address and subnet mask that appears in manual configurations, respectively. c) Field source indicates whether the destination connection is set to use DHCP or be configured manually. rem does not belong to netsh commands, and will cause an error when being processed, but it can be used as a mark of comments.

Step 2. 编写批处理脚本,调用netsh命令: write a shell batch file to call netsh and read the scripts above.

runnetsh.cmd

***

netsh -f "%~1"

***

Step 3. 在组策略编辑器中,将runnetsh.cmd加入关机脚本,并将disabledhcp.txt的完整路径名填写进“参数”字段。添加方法参考以下文章的Step 3

 2009/2/8
关机时清除临时文件
http://ddcspace.spaces.live.com/blog/cns!EAACF9754046F850!5416.entry

Go to Group Policy Editor, and add runnetsh.cmd into shut-down script, and fill the field "parameters" with the full-pathname of disabledhcp.txt.

Step 4. 在“开始菜单”的“启动”项中,加入runnetsh.cmd的快捷方式,并在快捷方式的命令行最后的最后,粘贴setdhcp.txt的完整路径名。Add a shortcut for runnetsh.cmd into "Start Menu > Startup", then paste the full-pathname of setdhcp.txt.

 

参考文章 References

关机时清除临时文件    http://ddcspace.spaces.live.com/blog/cns!EAACF9754046F850!5416.entry

Netsh commands for Interface IP  http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/netsh_int_ip.mspx?mfr=true

RFC 2131 – Dynamic Host Configuration Protocol  http://www.faqs.org/rfcs/rfc2131.html

– END –

Advertisements
  1. 留下评论

Log in or fill out contact info to leave a reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: