Solved

Help with creating script

Posted on 2007-04-06
6
181 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
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…

626 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