Solved

Help with creating script

Posted on 2007-04-06
6
179 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…

735 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