VBScript...Help!

Status
Not open for further replies.

Kelvarr

Ars Scholae Palatinae
938
Ok, I will preface this with the fact that I am NOT a programmer (as you will be able to tell by "my" code).

I have a *.hta file that runs after we image a computer that assigns IP address info (IP, SN, GW, DNS, WINS). I have everything running good, except for one part, and that is the WINS. I cannot get it to apply the WINS server for the life of me. Everything else is working as it should.

Please forgive code sloppiness. As I said, I am not a programmer. I found examples on the web and applied them, so certain parts may not even be needed. Here is the *.hta:

CFH/FarmHills stuff has DNS suffix and search order, plus a WINS server. Farmington/FarmDomain stuff does not. Just basic static IP.

I need WINS to work, and I cannot get it to
Code:
<SCRIPT LANGUAGE="VBScript">
Sub Window_OnLoad 
        Set wshShell = CreateObject("WScript.Shell") 
        window.resizeTo 450,600

		
		Const wbemFlagReturnImmediately = &h10
	Const wbemFlagForwardOnly = &h20
	strComputer = "."
	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
	Set colItems = objWMIService.ExecQuery("SELECT Name,DeviceID FROM Win32_NetworkAdapter WHERE NetConnectionStatus=2", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
	For Each objItem In colItems
	strName = objItem.Name
    Set colNicConfigs = objWMIService.ExecQuery _
      ("ASSOCIATORS OF {Win32_NetworkAdapter.DeviceID='" & objItem.DeviceID & "'} WHERE AssocClass=Win32_NetworkAdapterSetting")
    For Each objItemConfig In colNicConfigs
		strSettingID = objItemConfig.SettingID
    Next
	Set mySpan = document.getelementbyid("AdapterInfo") 
	mySpan.InnerHtml = mySpan.InnerHtml & "<br>" & strSettingID & "<br>"
'	MsgBox strName & VbCrLf & strSettingID
Next
		
		End Sub 

Sub FarmHills
	SN.value = "255.255.0.0"
	GW.value = "10.2.1.1"
	DNS1.value = "10.2.2.40"
	DNS2.value = "10.2.2.59"
	CFHDomain
End Sub

Sub CFHDomain
	Set objwshShell = CreateObject("WScript.Shell")
	objWshShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\SearchList", "fhgov.com","REG_SZ"
		

	Dim objWMIService, objItem, colItems, strComputer, StrDNSDomain, strPrimaryServer

	strComputer = "." 
	StrDNSDomain = "fhgov.com"
	strWINS1 = "10.2.2.15"

	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
	Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration where IPEnabled=True")
	Set colActiveNic = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration where IPEnabled=True")
	
	On error Resume Next

	For Each objItem In colItems 
	'WScript.Echo objItem.DNSDomain 
	objItem.SetDNSDomain(StrDNSDomain) 
	objItem.SetWINSServer(strWINS1)
	Next
	CFHWINS	
End Sub

Sub CFHWINS
On Error Resume Next 
 
strComputer = "." 
Set objWMIService = GetObject("winmgmts:" _ 
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
 
Set colNetCards = objWMIService.ExecQuery _ 
    ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True") 
 
For Each objNetCard in colNetCards 
    strPrimaryServer = "10.2.2.15" 
        objNetCard.SetWINSServer(strPrimaryServer)
Next 
End Sub	

Sub Farmington
	SN.value = "255.255.255.0"
	GW.value = "172.18.47.1"
	DNS1.value = "172.18.47.129"
	DNS2.value = "172.16.206.10"
	FarmDomain
End Sub

Sub FarmDomain
	Set objwshShell = CreateObject("WScript.Shell")
	objWshShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\SearchList", "","REG_SZ" 
	
	Dim objWMIService, objItem, colItems, strComputer, StrDNSDomain, strPrimaryServer

	strComputer = "." 
	StrDNSDomain = ""
	strWINS1 = ""

	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
	Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration where IPEnabled=True")

	On error Resume Next

	For Each objItem In colItems 
	'WScript.Echo objItem.DNSDomain 
	objItem.SetDNSDomain(StrDNSDomain)
	objItem.SetWINSServer(strWINS1)
	Next
	FarmWINS
End Sub
		
Sub FarmWINS
On Error Resume Next 
 
strComputer = "." 
Set objWMIService = GetObject("winmgmts:" _ 
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
 
Set colNetCards = objWMIService.ExecQuery _ 
    ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True") 
 
For Each objNetCard in colNetCards 
    strPrimaryServer = "" 
        objNetCard.SetWINSServer strPrimaryServer
Next 
End Sub	
		
Sub Network

Input1 = BasicTextbox(0).Value
Input2 = BasicTextbox(1).Value
Input3 = BasicTextbox(2).Value
Input4 = BasicTextbox(3).Value
Input5 = BasicTextbox(4).Value

For Each NetworkAdapter In GetObject("winmgmts:").InstancesOf("Win32_NetworkAdapter")
If NetworkAdapter.AdapterType = "Ethernet 802.3" Then
For Each AdapterConfiguration In GetObject("winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")
If UCase(AdapterConfiguration.ServiceName) = UCase(NetworkAdapter.ServiceName) Then
IPAddress = Array(Input1)
SubnetMask = Array(Input2)
Gateway = Array(Input3)
DNS = Array(Input4,Input5)



RetVal = AdapterConfiguration.EnableStatic(IPAddress, SubnetMask)
If Not RetVal = 0 Then 
MsgBox "Failure assigning IP/Subnetmask."
End If
RetVal = AdapterConfiguration.SetGateways(Gateway)
If Not RetVal = 0 Then 
MsgBox "Failure assigning Gateway."
End If
RetVal = AdapterConfiguration.SetDnsServerSearchOrder(DNS)
If Not RetVal = 0 Then 
WScript.Echo "Failure assinging DNS search order."
End If
End If
Next

End If

Next
MsgBox "IP Address: " & Input1 & (Chr(10)) & "Subnet Mask: " & Input2 & (Chr(10)) & "Gateway: " & Input3 & (Chr(10)) & (Chr(10)) & "Successful!"
'wscript.echo "IP Address: " & Input1 & (Chr(10)) & "Subnet Mask: " & Input2 & (Chr(10)) & "Gateway: " & Input3 & (Chr(10)) & (Chr(10)) & "Successful!" & (Chr(10)) & (Chr(10)) & "Please press OK to Set up a User account"
'Myvar=MsgBox ("IP Address: " & Input1 & (Chr(10)) & "Subnet: " & Input2 & (Chr(10)) & "Gateway: " & Input3 & (Chr(10)) & (Chr(10)) & "Successfully Assigned!" & (Chr(10)) & (Chr(10)) & "Please Press OK to Set up a User or Cancel to skip", 1,"Setting up IP and User Information")
'If myvar=1 then

'Self.Close()

End Sub
'_________________________________________________________________________
Sub CancelScript
   Self.Close()
End Sub




</SCRIPT>


<BODY>
<input id=runbutton class="button" type="button" value="Farmington Hills" name="ok_button" 
onClick="FARMHILLS">
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;


<input id=runbutton class="button" type="button" value="Farmington" name="ok_button" 
onClick="Farmington"><br><br>



<b>Please enter the IP Address:</b><br>
<input type="text" name="BasicTextbox" size="30"><br>
<b>Please enter the Subnet Mask:</b><br>
<input type="text" id="SN" name="BasicTextbox" size="30"><br>
<b>Please enter the Gateway:</b><br>
<input type="text" id="GW" name="BasicTextbox" size="30"><br>
<br><p>
<b>Please enter the DNS1:</b><br>
<input type="text" id="DNS1" name="BasicTextbox" size="30"><br>
(CFH: 10.2.2.40)<br>
(CoF: 172.18.47.129)<br><br>
<b>Please enter the DNS2:</b><br>
<input type="text" id="DNS2" name="BasicTextbox" size="30"><br>
(CFH: 10.2.2.59)<br>
(CoF: 172.16.206.10)<br><br>




<br><p>
<br><p>
<input id=runbutton class="button" type="button" value="Assign IP" name="ok_button" 
onClick="Network">
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;

<input id=runbutton class="button" type="button" value="Next" name="cancel_button" 
onClick="CancelScript">

<br><p>
<span ID="AdapterInfo"></span>
</BODY>
 
Status
Not open for further replies.