Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Help with creating script

Posted on 2007-04-06
6
Medium Priority
?
182 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 2000 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
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 while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

661 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