Solved

Help with creating script

Posted on 2007-04-06
6
173 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
  • 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
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 …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now