Code Script .co.uk

Home | Scripts | Tutorials | Disclaimer | Sitemap | Contact

   Set All Network Adapters To Dhcp
 

Vbscript / General / Set All Network Adapters To Dhcp

Sets all network interfaces (NICS) to aquire their IP address by DHCP on the specified computer.


On Error Resume Next
 
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\" & strComputer & " ootcimv2")
Set colNicConfs = objWMIService.ExecQuery _
  ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
 
strStatus = ""

For Each objNicConf In colNicConfs

    strStatus =  strStatus & "Network Adapter: " & objNicConf.Index & VbCrLf & objNicConf.Description & VbCrLf

    If Not objNicConf.DHCPEnabled Then
        WScript.Echo "    Enabling DHCP ..."
        intStatus = objNicConf.EnableDHCP

        If intStatus = 0 Then
            strStatus = strStatus & " - DHCP enabled successfully"
        Else
            strStatus = strStatus & " - Cannot enable DHCP"
        End If
 
    Else
        strStatus = strStatus & "DHCP already enabled with Server: " & objNicConf.DHCPServer
    End If
strStatus = strStatus & VbCrLf & VbCrLf
Next

Wscript.Echo strStatus





Please note that a disclaimer applies to any code on this page.
 
   Actions
  Go Back
  Bookmark
  Print Page


   Menu
 
- Links
- Reference
- Script Editors
- Tutorials
- Vbscript
     - Active Directory
     - Exchange
     - Files And Folders
     - General
          - Check Remote Computer Disks
          - Encode Hardcoded Passwords
          - Generate Random Password
          - Get Machine Ip Address
          - Get Machine Ip Address From Name
          - Print All Files In A Folder
          - Run Chkdsk
          - Set All Network Adapters To Dhcp
          - Sql Server Query
          - Vbscript Logging Techniques
     - Ms Office
     - Operating System
     - Processes And Services
     - Text Processing
     - User Interaction
     - Web Servers


Keywords: NIC to DHCP, Set Network Card, NW Card, Turn on DHCP,