# VBS - Help me fix strComputer = "." to instead target multiple computers in a list.



## StumpedTechy

Okay I have a code I need to run on the network but I need it to be perfect before I run it - The code I found itself all looks ready except for this part -

strComputer = "."

I know this will run the code through only on my computer (or am I wrong?)... I want to run this only on certain computers over the network...

Can I make a list of computernames in a text file and have it actually run through each computer?

Here is the code -



Code:


On Error Resume Next

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

For Each objNetAdapter In colNetAdapters
errEnable = objNetAdapter.EnableDHCP()
objNetAdapter.SetDynamicDNSRegistration FULL_DNS_REGISTRATION, _
DOMAIN_DNS_REGISTRATION

Next

Basically we are switching from Static to pure DHCP except for printers and main servers... but were not doing the DHCP at all sites at once (to ensure no fallout) so I can't have this "run rampant".

The next thing I want to find out is can I also use WMI to remove the IPX/SPX compatible protocol from a machine remotely as well?


----------



## Mithrilhall

Try



Code:


strComputer = "ComputerName"

where ComputerName is a name of one of the computers on your network.

If that works you could easily create a text file with 1 computer name on each line.

Then in the VBScript you could open the file and put a loop in your code that would read each line and execute the code for each computer name.


----------



## StumpedTechy

Thank you but can you tell me "how"

I know it works I have put in a number of computer names on "." and it works on each test...

What I don't know is how to get strComputer to get information from a file 

at the end I know you can do a loop command but what keeps it from getting the same computername...

would it be like something like For each X in file = strComputer?


----------



## Mithrilhall

Check out the FileSystemObject.

http://www.aspfaqs.com/aspfaqs/ShowCategory.asp?CatID=4

This page deals with asp but you can alter the code with very very little effort to get it to do what you want.

Just read the text file to eof (End of File).

Example I wrote a while back using FileSystemObject:



Code:


Set oHTML = CreateObject("MSXML2.XMLhttp")
oHTML.Open "GET", "http://www.whatismyip.com", False
oHTML.Send
sText = Split(oHTML.ResponseText, "<TITLE>")
sIP   = Mid(sText(1), 12, 14)
'WScript.Echo Mid(sText(1), 12, 15)
Set oHTML = Nothing
'WScript.Quit

Set objFSO = CreateObject("Scripting.FileSystemObject")

'Create the text file
'Set objTS = objFSO.CreateTextFile("C:\Documents and Settings\eric\Desktop\IP.txt")
Set objTS = objFSO.OpenTextFile("C:\Documents and Settings\eric\Desktop\IP.txt", 8, True)

objTS.WriteLine(Trim(sIP) & " - " & Now())

'Clean up
objTS.Close
Set objTS = Nothing
Set objFSO = Nothing

WScript.Quit


----------



## asbo

Here, this should do what you're asking.


Code:


On Error Resume Next

Set objGetComputerList = CreateObject("Scripting.FileSystemObject")
Set fsoReadComputerList = objGetComputerList.OpenTextFile("computers.txt", 1, TristateFalse)
aryComputers = Split(fsoReadComputerList.ReadAll, vbCrLf)
fsoReadComputerList.Close
    
For Each strComputer In aryTasks
	'strComputer = "."
	Set objWMIService = GetObject("winmgmts:" _
	& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

	Set colNetAdapters = objWMIService.ExecQuery _
	("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

	For Each objNetAdapter In colNetAdapters
		errEnable = objNetAdapter.EnableDHCP()
		objNetAdapter.SetDynamicDNSRegistration FULL_DNS_REGISTRATION, _
		DOMAIN_DNS_REGISTRATION

	Next
Next

Just create `computers.txt` with one computer per line and you're set.


----------

