VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



WMI sample: change wins and dns on local or remote computer. Written in VBScript. Uses Win32_Networ

by Anonymous (267 Submissions)
Category: Internet/HTML
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Sun 4th May 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)

WMI sample: change wins and dns on local or remote computer. Written in VBScript. Uses Win32_NetworkAdapterConfiguration WMI class.

Rate WMI sample: change wins and dns on local or remote computer. Written in VBScript. Uses Win32_Networ



' IMPORTANT !!!! Change these constants !!!!
Const STR_SERVERS = "server1 server2 "  ' Enter your servers here, separated by a space
Const STR_NEWDNS1 = "192.168.1.1" 
Const STR_NEWDNS2 = "192.168.1.2"
Const STR_NEWWINS1= "192.168.1.3" 
Const STR_NEWWINS2= "192.168.1.4"
 
' ///////////////////////////////////////////////////////////////////////////////////////////////
Do
cKeuze = MakeChoise( "Choose: Report or Change (R/C)?" )
Loop until cKeuze = "C" Or cKeuze = "R"
WScript.Echo
If( cKeuze = "C" ) Then
Change( STR_SERVERS )
Else
Report( STR_SERVERS )
End If
WScript.Echo( "Check out http://www.activexperts.com for more samples and components" )
' ///////////////////////////////////////////////////////////////////////////////////////////////


' ///////////////////////////////////////////////////////////////////////////////////////////////
Sub Change( strParamServers )
arrServers = Split( strParamServers, " " )
For i = 0 To UBound( arrServers )
ShowDnsWins arrServers( i )
Do
cKeuze = MakeChoise( "  Change DNS/WINS and reboot (y/n)?" )
Loop until cKeuze = "Y" Or cKeuze = "N"
If( cKeuze = "Y" ) Then
SetDnsWins arrServers( i )
RebootServer( arrServers( i ) )
End If

    WScript.StdOut.Write( vbCrlf )
Next
End Sub
' ///////////////////////////////////////////////////////////////////////////////////////////////
Sub Report( strParamServers )
arrServers = Split( strParamServers, " " )
For i = 0 To UBound( arrServers )
ShowDnsWins arrServers( i )
Next
End Sub
' ///////////////////////////////////////////////////////////////////////////////////////////////
Sub ShowDnsWins( strServer )
strWinMgmt = "winmgmts:{impersonationLevel=impersonate}!//"& strServer &""
Set objNICs = GetObject( strWinMgmt ).InstancesOf( "Win32_NetworkAdapterConfiguration" )
WScript.StdOut.Write( strServer & ": " & vbCrlf )
For Each objNIC In objNICs
If objNIC.IPEnabled Then
WScript.StdOut.Write( "  " & objNIC.Description & ": " & vbCrlf & "    " )
            n = 1
    For Each strDns In objNIC.DNSServerSearchOrder 
    WScript.StdOut.Write "DNS" & n & ":" & strDns & " "
    n = n + 1
Next
WScript.StdOut.Write( vbCrlf )
End If
Next
WScript.StdOut.Write( vbCrlf )
End Sub
' ///////////////////////////////////////////////////////////////////////////////////////////////
Sub SetDnsWins( strServer )
strWinMgmt = "winmgmts:{impersonationLevel=impersonate}!//"& strServer &""
Set objNICs = GetObject( strWinMgmt ).InstancesOf( "Win32_NetworkAdapterConfiguration" )

WScript.StdOut.Write( "  Set DNS for NIC: " )
For Each objNIC In objNICs
If objNIC.IPEnabled Then
objNIC.SetWINSServer STR_NEWWINS1,STR_NEWWINS2
objNIC.SetDNSServerSearchOrder Array(STR_NEWDNS1,STR_NEWDNS2)
WScript.StdOut.Write objNIC.Description & "  " 
End If
Next
WScript.StdOut.Write( vbCrlf )
End Sub
' ///////////////////////////////////////////////////////////////////////////////////////////////
Sub RebootServer( strServer )
Set OpSysSet = GetObject("winmgmts:{(RemoteShutdown)}//" & strServer & "/root/cimv2").ExecQuery("Select * from Win32_OperatingSystem where Primary=True")
WScript.StdOut.Write( "  Reboot: " )
For Each OpSys In OpSysSet
WScript.StdOut.Write OpSys.Name
OpSys.Reboot()
Next
WScript.StdOut.Write( vbCrlf )
End Sub
' ///////////////////////////////////////////////////////////////////////////////////////////////
Function MakeChoise( strMesg )
WScript.StdOut.Write(strMesg)
WScript.StdIn.Read(0)
strChoise = WScript.StdIn.ReadLine()
MakeChoise = UCase( Left( strChoise, 1 ) )
End Function




Download this snippet    Add to My Saved Code

WMI sample: change wins and dns on local or remote computer. Written in VBScript. Uses Win32_Networ Comments

No comments have been posted about WMI sample: change wins and dns on local or remote computer. Written in VBScript. Uses Win32_Networ. Why not be the first to post a comment about WMI sample: change wins and dns on local or remote computer. Written in VBScript. Uses Win32_Networ.

Post your comment

Subject:
Message:
0/1000 characters