Use the FileSystemObject to read a text file, one line at a time. For example: ================ Const ForReading = 1
' Specify file of computer NetBIOS names. strFile = "c:\scripts\computers.txt"
' Open file for read access. Set objFSO = CreateObjectg("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(strFile, ForReading)
' Read each line of the file. Do Until objFile.AtEndOfStream strComputerName = Trim(objFile.ReadLine) ' Skip blank lines. If (strComputerName <> "") Then ' Perform tasks on this computer. ' ...
End If Loop
' Clean up. objFile.Close
-- Richard Mueller Microsoft MVP Scripting and ADSI Hilltop Lab - http://www.rlmueller.net --
<Jack.Merchant[ at ]gmail.com> wrote in message news:1182972748.567601.112070[ at ]j4g2000prf.googlegroups.com...
[Quoted Text] >I want to use the script below with WMI to change the startup type of > some services across our domain on multiple computers. How can I > specify to read the computer name from a text file? > > '############################# > 'Function ChangeServiceStartOption > 'Variables > 'ComputerName > 'ServiceName - Service Display Name > 'StartOption - "Automatic","Manual","Disabled" > > 'Returns > '0 if service's start option is changed successfully > '1 if it is not changed successfully > '2 if service does not exist on the remote machine > '3 if unable to connect to the remote machine > > 'NOTE: This function searchs for the Service DISPLAY NAME, not the > actual name. > ' To change that, just replace DisplayName with Name > > > Function ChangeServiceStartOption(ComputerName,ServiceName, > StartOption) > On Error Resume Next > > 'Create a WMI object to connect to the computer > Set objWMIService = GetObject("Winmgmts:\\" & ComputerName & "\root > \cimv2") > If Err.Number = 0 Then > > 'Retrieve a collection of Services using the ExecQuery method. > Set colServices = objWMIService.ExecQuery("SELECT * FROM Win32_Service > Where DisplayName = '" & _ > ServiceName & "'") > > 'Check to see if the service was found > If colServices.Count <> 0 Then > > 'Loop through the collection of Services (should only be one) > For Each Service in colServices > > 'Change the service start option > errCode = Service.Change( , , , , StartOption) > If errCode = 0 Then > ChangeServiceStartOption = "0" > Else > ChangeServiceStartOption = "1" > End If > > Next > > 'Service Not Found > Else > ChangeServiceStartOption = "2" > End If > > Else > ChangeServiceStartOption = "3" > Err.Clear > End If > > > End Function > > '############################# > > Thanks >
|