#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    37
    Rep Power
    12

    Change IP address using vbscript


    Hi,

    Apologies if this post is in the wrong area. I'm very new to VB scripting so looking for any help whatsoever.

    My aim is to write a HTA to change the local IP address/subnet mask/default gateway from one of 3 presets. Ultimately, the presets will need to be variable so the user can modify them in the future.

    I have a working script to change the IP details as follows:

    Code:
    Option Explicit
    Dim objWMIService
    Dim objNetAdapter
    Dim strComputer
    Dim arrIPAddress
    Dim arrSubnetMask
    Dim arrGateway
    Dim colNetAdapters
    Dim errEnableStatic
    Dim errGateways
    
    strComputer = "."
    arrIPAddress = Array("10.240.2.40")
    arrSubnetMask = Array("255.255.255.0")
    arrGateway = Array("10.240.2.200")
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colNetAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
    For Each objNetAdapter in colNetAdapters
         errEnableStatic = objNetAdapter.EnableStatic(arrIPAddress, arrSubnetMask)
         errGateways = objNetAdapter.SetGateways(arrGateway)
    Next
    Obviously I can copy the script three times with different IP addresses, but I need to make the settings variable using an input box and store these details for future use. Some form of config file is my first thought, but I wouldn't know how to go about getting the script reading/writing from/to the file.

    Any help or pointers towards existing scripts I can modify is very much appreciated.

    Cheers

    Andy
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    37
    Rep Power
    12
    I found a script that does exactly what I needed...

    For those who are looking to do something similar, the following script to read/write .ini files works a treat and is simple to use:

    http://www.robvanderwoude.com/vbstech_files_ini.html

    Cheers
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Posts
    1
    Rep Power
    0
    where do you put code keep on getting a error
  6. #4
  7. Type Cast Exception
    Devshed Supreme Being (6500+ posts)

    Join Date
    Apr 2004
    Location
    OAKLAND CA | Adam's Point (Fairyland)
    Posts
    14,954
    Rep Power
    8617
    This thread is four years old Solaris, I doubt you'll get a reply from the original correspondent.

    VBScript of course goes in a plain text file, you name it .vbs and execute that.
    medialint.com

    “Today you are You, that is truer than true. There is no one alive who is Youer than You.” - Dr. Seuss
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    how do you change a web ip adress ?


    yo i was wondering if uh could change a web ip adress ?

IMN logo majestic logo threadwatch logo seochat tools logo