Announcement

Collapse
No announcement yet.

Change the IP and DNS setting from static into dynamic using DHCP

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Change the IP and DNS setting from static into dynamic using DHCP

    Hello All,

    I'd like to know if it is possible to reset the current statically assigned DNS Server on the workstation using a script ?

    I've been suggested by some experts a script like the following:

    Code:
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colNetAdapters = objWMIService.ExecQuery _
    ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
    For Each objNetAdapter In colNetAdapters
    	errEnable = objNetAdapter.EnableDHCP()
    	If errEnable = 0 Then
    		Wscript.Echo "DHCP has been enabled."
    	Else
    		Wscript.Echo "DHCP could not be enabled."
    	End If
    Next
    Source: but it can only reset the static IP address into DHCP but not the DNS server.

    Any help please ?

    Thanks.

  • #2
    Re: Change the IP and DNS setting from static into dynamic using DHCP

    Have another look at netsh, which i provided in the same post.

    Comment


    • #3
      Re: Change the IP and DNS setting from static into dynamic using DHCP

      Originally posted by wullieb1 View Post
      Have another look at netsh, which i provided in the same post.
      Ah.. do you mean the following code:

      Code:
      netsh interface ip set dns "Local Area Connection" dhcp
      netsh interface ip set wins "Local Area Connection" dhcp
      netsh interface ip set address "Local Area Connection" dhcp
      ipconfig /renew
      but the code won't be working properly if the name of the LAN adapter is not default name

      Comment


      • #4
        Re: Change the IP and DNS setting from static into dynamic using DHCP

        By using WMI and/or netsh you'll probably catch better than 90% of the workstations that have an interface named "Local Area Connection". For the ones that don't you'll have to manually change them to DHCP by visting them or walking the user through changing them. While it would be nice to automate it for all of the workstations, it just might not be possible. Sometimes that's how it goes.

        Comment


        • #5
          Re: Change the IP and DNS setting from static into dynamic using DHCP

          So why not use VB to get the name of the connection and then use that string to run netsh.

          Surely it could be done somehow.

          Comment


          • #6
            Re: Change the IP and DNS setting from static into dynamic using DHCP

            Originally posted by Albertwt View Post
            should I go and tell everyone in the company to make the IP Addressing configuration changes or there is a script that can be configured as the "logon" script that i can put into the GPO ?
            1. Configure to run the script as Computer Startup script instead of logon script.


            2.
            a) When using vbs - you can enable dhcp and, you also have to empty the array of configured dns servers "SetDNSServerSearchOrder()" for all ip-enabled nics. ( http://forums.petri.com/showpost.php...79&postcount=3 / http://www.microsoft.com/downloads/d...displaylang=en )

            b) When using a batch - you can use wmic instead of netsch (windows XP or above). For the the WMIC commmand line you can use the WMI classes you also use with vbs. http://forums.petri.com/showpost.php...8&postcount=25


            As an alternative for using a startup-script, it would also be possible to run the WMIC command lines or the vbs-script as an administrator against a list of target machines.


            \Rems
            Last edited by Rems; 22nd June 2009, 22:58.

            This posting is provided "AS IS" with no warranties, and confers no rights.

            __________________

            ** Remember to give credit where credit's due **
            and leave Reputation Points for meaningful posts

            Comment


            • #7
              Re: Change the IP and DNS setting from static into dynamic using DHCP

              thanks to all for the reply.

              Comment


              • #8
                Re: Change the IP and DNS setting from static into dynamic using DHCP

                Hi ,
                i am using this script to assign IP, Netmask, gateway, and DNS

                ================================================
                @echo created by: Aman Dhally, appying office profile, please wait. . .
                @echo off
                color 20
                netsh interface ip set address "Local Area Connection" static 192.168.1.95 255.255.255.0 192.168.1.7 1
                netsh interface ip set dns "Local Area Connection" static 192.168.1.7
                ================================================== =

                Thanks

                Comment


                • #9
                  Re: Change the IP and DNS setting from static into dynamic using DHCP

                  Hi Amand,

                  Your script looks like it is for assigning static IP ?

                  but thanks for submitting it anyway

                  Comment


                  • #10
                    Re: Change the IP and DNS setting from static into dynamic using DHCP

                    Yep thats what its doing alright.

                    And i hope you don't run it on anymore than one machine or you will start having problems.

                    Comment

                    Working...
                    X