Results 1 to 7 of 7

Thread: Setting IP Address using VB

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Location
    Philippines
    Posts
    70

    Setting IP Address using VB

    can someone help me on how to set IP address using VB thanks

  2. #2
    Hyperactive Member Teseng's Avatar
    Join Date
    Sep 2007
    Location
    Tupelo, MS
    Posts
    281

    Re: Setting IP Address using VB

    set IP address of what?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Location
    Philippines
    Posts
    70

    Re: Setting IP Address using VB

    set IP address of my computer...

  4. #4
    Hyperactive Member Teseng's Avatar
    Join Date
    Sep 2007
    Location
    Tupelo, MS
    Posts
    281

    Re: Setting IP Address using VB

    You could change the LAN address using some API's probably. What exactly do you want to achieve as the end result?

    _Pulled this code from google
    Code:
    Dim objWMIService, colNetAdapters, objNetAdapter
    Dim strIPAddress, strSubnetMask, strGateway, strGatewaymetric
    Dim errEnable, errGateways
    Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
    Set colNetAdapters = objWMIService.ExecQuery _
        ("Select * from Win32_NetworkAdapterConfiguration " & "where IPEnabled=TRUE")
           
    strIPAddress = Array("192.168.1.141")
    strSubnetMask = Array("255.255.255.0")
    strGateway = Array("192.168.1.1")
    strGatewaymetric = Array(1)
     
    For Each objNetAdapter In colNetAdapters
        errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
        errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
    Next
    Edit: Seems to work. Does however break DNS server, work with it and see what you can get maybe
    Last edited by Teseng; Jun 5th, 2008 at 06:19 AM.

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Setting IP Address using VB

    If you programmatically change the IP address of your computer, isn't that going to mess up connections for you? Do you have a static IP, or are you using DHCP?

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Setting IP Address using VB

    Probably not as its probably the local ip of the workstation and not the router.

    You can also shellexecute the cmd.exe and pass the ipconfig /release amd then another one with ipconfig / renew but this wont let you specify the ip address.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7
    Fanatic Member
    Join Date
    Jan 2007
    Location
    Middletown, CT
    Posts
    948

    Re: Setting IP Address using VB

    or you could just use shell and "netsh interface ip set address" ......

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width