Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8580345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:48:34+00:00 2026-06-11T20:48:34+00:00

How can I set my IP address programmatically? My application is checking it, using

  • 0

How can I set my IP address programmatically?

My application is checking it, using code from DelphiTricks (although I am not sure if the code from About.com might not be better)

I want to be able to set the address programmatically for testing purposes. And (I don’t know if this is important), I want to be able to do so even I am not attached to any network (on a laptop, on a train).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:48:35+00:00Added an answer on June 11, 2026 at 8:48 pm

    To change the ip address of your network adapter you can use the EnableStatic method of the Win32_NetworkAdapterConfiguration WMI class or the AddIPAddress WinApi method.

    Try this sample which uses the WMI.

    {$APPTYPE CONSOLE}
    
    {$R *.res}
    
    uses
      SysUtils,
      ActiveX,
      Variants,
      ComObj;
    
    procedure  SetStaticIpAddress(const NetworkCard, IPAddress, Mask :string);
    const
      WbemUser    ='';
      WbemPassword='';
      WbemComputer='localhost';
      wbemFlagForwardOnly = $00000020;
    var
      FSWbemLocator   : OLEVariant;
      FWMIService     : OLEVariant;
      FWbemObjectSet  : OLEVariant;
      FWbemObject     : OLEVariant;
      FOutParams      : OLEVariant;
      vIpAddress      : OLEVariant;
      vMask           : OLEVariant;
      oEnum           : IEnumvariant;
      iValue          : LongWord;
    begin
      FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
      FWMIService   := FSWbemLocator.ConnectServer(WbemComputer, 'root\CIMV2', WbemUser, WbemPassword);
    
      FWbemObjectSet:= FWMIService.ExecQuery(Format('SELECT * FROM Win32_NetworkAdapterConfiguration Where Description="%s"',[NetworkCard]),'WQL',wbemFlagForwardOnly);
      oEnum         := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
      if oEnum.Next(1, FWbemObject, iValue) = 0 then
      begin
        vIpAddress   := VarArrayCreate([0, 0], varVariant);
        vIpAddress[0]:= IPAddress;
        vMask   := VarArrayCreate([0, 0], varVariant);
        vMask[0]:=  Mask;
        FOutParams:=FWbemObject.EnableStatic(vIpAddress, vMask);
        // 0 - Successful completion, no reboot required
        // 1 - Successful completion, reboot required
        Writeln(Format('ReturnValue  %s',[FOutParams]));
      end
      else
      Writeln('Network card not found');
    end;
    
    
    begin
     try
        CoInitialize(nil);
        try
          SetStaticIpAddress('Network card name','192.168.1.1','255.255.255.0');
        finally
          CoUninitialize;
        end;
     except
        on E:EOleException do
            Writeln(Format('EOleException %s %x', [E.Message,E.ErrorCode]));
        on E:Exception do
            Writeln(E.Classname, ':', E.Message);
     end;
     Writeln('Press Enter to exit');
     Readln;
    end.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand that we can set the various style attributes from code behind using
How can you display a long string, website address, word or set of symbols
I can set the event on the calendar on my device by using this
I want to set the IP address, subnet and gateway using netsh. I have
By using strace and ifconfig , I found that I can set the IP
I am using symfony 1.0.6 and in action file we can set error using,
Hi I need to set proxy address of IE programmatically Earlier I used to
I can set my usual email address in my ~/.hgrc file, but is there
In microchip C30 compiler i can set pin i/o value using LAT register in
Those fine RFCs mandate from every RFC-client that they beware of not using more

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.