views:

73

answers:

2

i want to write a batch which will have the same effect as follows. Here's what I do manually (which I want to program to do automatically):

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.
+2  A: 

Maybe this particular job is done best using a GUI based macro recorder. Otherwise, the most powerful instrument for manipulating Windows using scripts is WMI and the WMI console. It's quite complex however, check Wikipedia for more information. These two links might get you started:

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

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

Pekka
For this kind of task `netsh` is much better suited than WMI. Networking is a weird thing in that you have to use about 4 or 5 different tools to get a overview of the complete system. Not much nicer than the mess in unixoid systems here.
Joey
+2  A: 

Taken from here: http://support.microsoft.com/kb/257748

You can use netsh to perform all of the network setting manipulation. For example:

netsh interface ip set address "Local Area Connection" static 192.168.0.10 255.255.255.0 192.168.0.1 1
Michael Baker
+1 Didn't know that.
Pekka
Has one problem though: You have to hard-code the name of the network adapter you're modifying. I didn't find a good solution to obtain that one automatically (a naive solution fails miserably even when no WiFi adapter is present)
Joey
Yes but not an insurmountable problem. You could dump the netsh config to a file, parse it etc or just display all running profiles, and set the name to a command line variable for example.
Michael Baker