Solved

Help with creating script

Posted on 2007-04-06
6
180 Views
Last Modified: 2013-11-25
I am a beginner script writer and I would like to write a script that will insert the IP address of computer in the WINS and DNS part of the TCP/IP configuration for Windows XP OS. The reason is this is a lab environment and instead sitting down at 50 computers I figure a script will be better. What is the best scripting language to use and why?
0
Comment
Question by:tupac1979
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 18863599
The 'best' - is really an opinionated question...best answered by you... ;^)

Here's a script that should work though:

Const HKLM = &H80000002
Dim objShell:Set objShell = CreateObject("Wscript.Shell")
Dim objReg:Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
strKeyPath = "System\CurrentControlSet\Services\Tcpip\Parameters\Interfaces"
NewDNS = "192.168.1.1"
ProcessSubKey (strKeyPath)
Set objReg = Nothing
Set objShell=Nothing
wscript.quit

Sub ProcessSubKey(strKeyPath)
  objReg.EnumKey HKLM, strKeyPath, arrSubKeys
  If IsArray(arrSubKeys) Then
    For Each Key In arrSubKeys
    strPath = strKeyPath & "\" & Key
      ProcessSubKey (strPath)
         objReg.EnumValues HKLM, strPath, arrValues
         For Each Value In arrValues
            If Value = "IPAddress" Then
                arrValue = objShell.RegRead("HKLM\" & strPath & "\" & Value)
                For Each Item In arrValue
                  strItem = Replace(Item, "0.0.0.0", "") & strItem
                Next
                If strItem <> "" Then objShell.RegWrite "HKLM\" & strPath & "\NameServer", NewDNS
            End If
         Next
    Next
  End If
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18863615
Otherwise, a dos batch solution could be something like:

netsh int ip set dns "Local Area Network" static 192.168.1.1 primary

http://www.petri.co.il/configure_tcp_ip_from_cmd.htm gives good instruction on setting dns/wins from the command-line (or batch file)
0
 

Author Comment

by:tupac1979
ID: 18863849
Sirbounty what program did you write the first code in and thanks for your help I definitely have a much better understanding now.
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 67

Expert Comment

by:sirbounty
ID: 18863905
First is just vbscripting - save it as updatedns.vbs.  Just modify the NewDNS entry to update.
I didn't find Wins with that route though, so netsh may be the better option for you...
Users will need permissions to apply this though - may be best as a startup vs logon script
0
 

Author Comment

by:tupac1979
ID: 18863994
Thanks!!! once again you have been a big help. PEACE
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18864008
:^)
Happy to help - thanx for the grade!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
The viewer will learn how to dynamically set the form action using jQuery.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question