' --------------------------------------------------------------------------------
' Script:	setTcpAck.vbs
' Purpose:	Simple little script to clear tcpacktick delays for SMB
' Author:	Hyperus
' Notes:	No Liability Accepted for use under any circumstances
' --------------------------------------------------------------------------------
'
Option Explicit

'Const vbYesNo = 4
'Const vbYes = 6
'Const vbNo = 7

Dim objWMIService,colOperatingSystems,objOperatingSystem
Dim nResponse,OSVersion
Dim oShell,sNIC, n

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
    OSVersion = Left(objOperatingSystem.Version,3)
Next

Set objWMIService = nothing
Set colOperatingSystems = nothing
Set objOperatingSystem = nothing

nResponse = MsgBox("Clear TcpAck Delays on this machine. Is this what you want to do?" & vbCRLF & vbCRLF & "Click Yes to proceed or No to quit.", vbYesNo, "AddIP")
If nResponse = vbNo Then
	WScript.Echo "*** Script terminated by user ***"
	WScript.Quit 0
End If

Set oShell = WScript.CreateObject("WScript.Shell")

For n = 1 To 20
	sNIC = ""
	On Error Resume Next
	sNIC = oShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\" & CStr(n) & "\ServiceName")
	Err.Clear
	On Error Goto 0
	
	If sNIC <> "" Then
		WScript.Echo "Found Apapter [" & CStr(n) & "] " & sNIC
		Select Case OSVersion
			Case "5.0"
				oShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" & sNIC & "\TcpDelAckTicks",0,"REG_DWORD"
				wscript.echo "Writing : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" & sNIC & "\TcpDelAckTicks=0"
			Case "5.1"
				oShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" & sNIC & "\TcpAckFrequency",1,"REG_DWORD"
				wscript.echo "Writing : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" & sNIC & "\TcpAckFrequency=1"
			Case "5.2"
				oShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" & sNIC & "\TcpAckFrequency",1,"REG_DWORD"
				wscript.echo "Writing : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" & sNIC & "\TcpAckFrequency=1"
			Case "6.0"
				oShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" & sNIC & "\TcpAckFrequency",1,"REG_DWORD"
				wscript.echo "Writing : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" & sNIC & "\TcpAckFrequency=1"
			Case "6.1"
				oShell.RegWrite "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" & sNIC & "\TcpAckFrequency",1,"REG_DWORD"
				wscript.echo "Writing : HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" & sNIC & "\TcpAckFrequency=1"
			Case Else
				WScript.Echo "'" & OSVersion & "'" & " Operating System not Suppported for this Reg Hack"
		End Select
	
	End If
Next

Set oShell = Nothing

WScript.Echo "Done."

nResponse = MsgBox("The machine must be restarted before these changes will take effect." & vbCRLF & vbCRLF & "You must do this manually.", 0, "AddIP - Done!")
WScript.Quit 0

