用于配置我的网络设备的批处理文件

问题描述:

我想写一个批处理文件,其效果如下。 这是我做手工(我想程序自动执行):用于配置我的网络设备的批处理文件

1) START -> Run -> cmd (get command prompt) 
2) ipconfig /release 
3) START -> Connect to -> Show all connections 
4) Right-click "Local Area Network" and click "Properties" 
5) Highlight "Internet Protocol (TCP/IP) and click "Properties" 
6) Check box "Use the following IP Address" 
7) Enter "111.111.111.111" for IP address 
8) Enter "255.0.0.0" for Subnet mask 
9) Click OK, and Close. 
10) Wait 20 seconds 
11) START -> Connect to -> Show all connections 
12) Check box for "Obtain IP address automatically" 
13) Click OK, and close. 
14) Wait 20 seconds. 

也许这份工作是使用基于GUI的宏录制做得最好。 否则,使用脚本操作Windows的最强大的工具是WMI和WMI控制台。然而,这很复杂,请查看*以获取更多信息。这两个链接可能让你开始:

http://quux.wiki.zoho.com/WMIC-Snippets.html

http://codeslammer.wordpress.com/2008/02/21/wmic-a-hidden-gem/

+0

对于这种类型的任务'netsh'比WMI更适合。网络是一个奇怪的事情,因为您必须使用大约4或5种不同的工具才能了解整个系统。这里比unixoid系统中的混乱要好得多。 – Joey 2009-10-26 00:25:27

从这里摘自:http://support.microsoft.com/kb/257748

您可以使用netsh的执行所有的网络设置操作的。例如:

netsh interface ip set address "Local Area Connection" static 192.168.0.10 255.255.255.0 192.168.0.1 1 
+0

+1不知道。 – 2009-10-25 21:19:45

+0

虽然有一个问题:您必须硬编码您正在修改的网络适配器的名称。我没有找到一个很好的解决方案来自动获得该解决方案(即使没有WiFi适配器时,天真的解决方案也无法挽回) – Joey 2009-10-26 00:26:46

+0

是的,但并非不可逾越的问题。您可以将netsh配置转储到文件,解析它等,或者只显示所有正在运行的配置文件,并将名称设置为命令行变量。 – 2009-10-26 02:33:31