My method CreateScript will write all lines except for the three listed at the bottom.
Sub CreateScript
Dim objWMIService, arrIPAddress, colNetAdapters
Dim objNetAdapter, arrSubnetMask, errEnableStatic
Dim arrGateway, errGateways, fsow, line
ip = FindIP 'My function to lookup the ip. Works fine, no issues there.
arrIPAddress = Array(ip)
arrSubnetMask = Array("255.255.255.0")
arrGateway = Array(ip)
Set fsow = fso.OpenTextFile(strSigPath & "\" & user & ".wsf", 2, True)
fsow.WriteLine "<" & "job>" & "<" & "script language=" & chr(34) & "VBScript" & chr(34) & ">"
fsow.WriteLine "Dim arrIPAddress, arrSubnetMask, arrGateway, machinename colNetAdapters, errEnableStatic, objWMIService, objNetAdapter"
fsow.WriteLine "arrIPAddress = " & arrIPAddress(0) & "." & arrIPAddress(1) & "." & arrIPAddress(2) & "." & arrIPAddress(3) & ""
fsow.WriteLine "arrSubnetMask = Array(" & chr(34) & "255.255.255.0" & chr(34) & ")"
fsow.WriteLine "arrGateway = " & Array(ip) & ""
fsow.WriteLine "arrGateway(0) = 10"
fsow.WriteLine "arrGateway(3) = 250"
fsow.WriteLine "Set objWMIService = GetObject(" & chr(34) & "winmgmts:\\" & chr(34) & " & machinename & " & chr(34) & "\root\cimv2" & chr(34) & ")"
fsow.WriteLine "Set colNetAdapters = objWMIService.ExecQuery(" & chr(34) & "Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE" & chr(34) & ")"
fsow.WriteLine "For Each objNetAdapter in colNetAdapters"
fsow.WriteLine
fsow.WriteLine "errEnableStatic = objNetAdapter.EnableStatic(" & arrIPAddress & "," & arrSubnetMask & ")"
fsow.WriteLine "If Not errEnableStatic = 0 Then"
fsow.WriteLine "WScript.Echo" & chr(34) & "Failure assigning IP/Subnet." & chr(34)
fsow.WriteLine "End If"
fsow.WriteLine
fsow.WriteLine "errGateways = objNetAdapter.SetGateways(" & arrGateway & ")"
fsow.WriteLine "If Not errGateways = 0 Then"
fsow.WriteLine "WScript.Echo" & chr(34) & "Failure assigning Gateway." & chr(34)
fsow.WriteLine "End If"
fsow.WriteLine "Next"
fsow.WriteLine "WScript.Quit"
fsow.WriteLine "</sc" & "ript></job>"
End Sub '***** CreateScript
I've tried writing this code in several different ways, but I just can't get the following lines to write out to my wsf txt file. Every other line will write to the file perfectly. Why will my WriteLine
method not write those three lines?
fsow.WriteLine "arrIPAddress = " & arrIPAddress(0) & "." & arrIPAddress(1) & "." & arrIPAddress(2) & "." & arrIPAddress(3) & ""
fsow.WriteLine "errEnableStatic = objNetAdapter.EnableStatic(" & arrIPAddress & "," & arrSubnetMask & ")"
fsow.WriteLine "errGateways = objNetAdapter.SetGateways(" & arrGateway & ")"