Wednesday, March 20, 2013

VBScript to check if DNS Suffix check box on Network Adapter on IPv4 is enabled

' Checking if DNS Suffix check box on Network Adapter on IPv4 is enabled. Results are exported to C:\Windows\Support\Testing\CTTestImageLog1.txt
On Error Resume Next
Dim NetworkInterfaceID, RegKeyValue, Temp
Function KeyExists(key)
    Dim objShell
    On Error Resume Next
    Set objShell = CreateObject("WScript.Shell")
        objShell.RegRead (key)
    Set objShell = Nothing
    If Err = 0 Then KeyExists = True
End Function
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("C:\Windows\Support\Testing\CTTestImageLog1.txt")
set objFile = objFSO.OpenTextFile(strFile, 8, True)
objFile.WriteLine("Checking if DNS Suffix check box on Network Adapter on IPv4 is enabled. 1 - True; 0 - False ")
For i = 0 to 20
RegistryKeyName = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\" & i & "\"
If KeyExists(RegistryKeyName) Then
Reg= RegistryKeyName + "ServiceName"
NetworkInterfaceID = ReadReg(Reg)
RegKeyValue1 = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces\" + NetworkInterfaceID
'MsgBox(RegKeyValue1)
Reg1= RegKeyValue1 + "\RegisterAdapterName"
'MsgBox(Reg1)
NetworkInterfaceID1 = ReadReg(Reg1)
'MsgBox(NetworkInterfaceID1)
'Output results to a file
strFile = "C:\Windows\Support\Testing\CTTestImageLog1.txt"
set objFSO = CreateObject("Scripting.FileSystemObject")
set objFile = objFSO.OpenTextFile(strFile, 8, True)
IF NetworkInterfaceID1 = 1 Then
'MsgBox("True")
objFile.WriteLine(Reg1 & " = " & NetworkInterfaceID1 & " - TRUE")
Else
'MsgBox("False")
objFile.WriteLine(Reg1 & " = " & NetworkInterfaceID1 & " - FALSE")
End If
objFile.Close
'MsgBox "Done"
End If

Next

 'WScript.Echo Temp
 Function ReadReg(RegPath)
       Dim objRegistry, Key
       Set objRegistry = CreateObject("Wscript.shell")
       Key = objRegistry.RegRead(RegPath)
       ReadReg = Key
 End Function