Solved

Show ipconfig with a D4 program?

Posted on 2001-06-13
12
439 Views
Last Modified: 2010-04-06
Hi All,

Right now I have the dos program that is a part of the
system programs on my computer that will show  'ipconfig'. Is there any program written
in D4 that will do the same thing?

An example would be appreciated.

Delphi3
0
Comment
Question by:delphi3
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 5

Expert Comment

by:knowlton
ID: 6188857
This works, but the DOS Shell window displays, then disappears.

I think you have to modify the .PIF file or something to keep the window maximized...


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

uses
  ShellAPI;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShellExecute(handle, 'open', 'ipconfig.exe', PChar(''),
              PChar(AnsiString('c:\windows')), SW_MAXIMIZE);

end;

end.
0
 
LVL 4

Author Comment

by:delphi3
ID: 6189124
Really???
just a blink, of a  {$APPTYPE CONSOLE} ???
you wrote:
'I think you have to modify the .PIF file or something to keep the window maximized'
Not much of a clue here where to look or how to modify it if I have to.

This is not what I had in mind by my Q.

Delphi3
0
 
LVL 5

Expert Comment

by:knowlton
ID: 6189313
It would be _default.pif.

I meant to post as a comment, not an answer.
0
 
LVL 4

Author Comment

by:delphi3
ID: 6189577
Hi,
And truthfully, I have no idea what this means or what I need to make 'it would be _default.pif.

Where is this or where do I write this in the program???

I accept your wanting to post this as a comment and perhaps it should have been until we got everything straightend out. But at this point hang in here with me until I can get things 'fixed'.


Delphi3
0
 
LVL 22

Expert Comment

by:mnasman
ID: 6189681
Hello

  Try this also

winexec('command.com /c ipconfig', sw_shownormal);
0
 
LVL 17

Expert Comment

by:geobul
ID: 6189960
Hi,
Just a notice: there is 'WINIPCFG.EXE' in windows system directory which is windows version of ipconfig.

Regards, Geo
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 22

Expert Comment

by:mnasman
ID: 6190101
geobul, you will not find winipcfg in win2k, ipconfig come with win2k instead of it, winipcfg come with win 9x

Mohammed
0
 
LVL 17

Accepted Solution

by:
geobul earned 50 total points
ID: 6190430
Hi Mohammed, thanks for the info.

Hi Delphi3,
What about capturing the ipconfig.exe output? Is it appropriate to you? Here is the code:

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

// executes a dos app with an output redirection
function ExecDosAppOutRedirect(CmdLine: String; ShowMode: DWord; WaitToExit: Boolean; OutputFile: string): DWord;
var StartInfo: TStartupInfo;
  ProcInfo: TProcessInformation;
  SecAtrrs : TSecurityAttributes;
  pOutputFile : array[0..MAX_PATH] of char;
  hOutputFile : THandle;
begin
 try
  StrPCopy(pOutputFile, OutputFile);

  FillChar(SecAtrrs, SizeOf(SecAtrrs), #0);
  SecAtrrs.nLength              := SizeOf(SecAtrrs);
  SecAtrrs.lpSecurityDescriptor := nil;
  SecAtrrs.bInheritHandle       := True;

  hOutputFile := CreateFile(pOutputFile,
                            GENERIC_READ or GENERIC_WRITE,
                            FILE_SHARE_READ or FILE_SHARE_WRITE,
                            @SecAtrrs,
                            CREATE_ALWAYS,
                            FILE_ATTRIBUTE_TEMPORARY,
                            0);

  FillChar(StartInfo, SizeOf(StartInfo), 0);
  StartInfo.cb:=SizeOf(StartInfo);
  StartInfo.dwFlags:=STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;;
  StartInfo.wShowWindow:=ShowMode;
  StartInfo.hStdOutput  := hOutputFile;
  CreateProcess(nil, PChar(CmdLine), nil, nil, True, CREATE_NEW_CONSOLE or REALTIME_PRIORITY_CLASS,
                         nil, nil, StartInfo, ProcInfo);

  if WaitToExit then WaitForSingleObject(ProcInfo.hProcess, INFINITE);
  GetExitCodeProcess(ProcInfo.hProcess, Result);
 finally
  CloseHandle(hOutputFile);
  CloseHandle(ProcInfo.hProcess);
  CloseHandle(ProcInfo.hThread );
 end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ExecDosAppOutRedirect('ipconfig.exe /all', SW_HIDE, true, 'c:\myip.txt');
  Memo1.Lines.LoadFromFile('c:\myip.txt');
  DeleteFile('c:\myip.txt');
end;

end.

Regards, Geo
0
 
LVL 4

Author Comment

by:delphi3
ID: 6191151
Knowlton,
As I said earlier I need something that does not just blink.
Sorry for the reject.

Delphi3
0
 
LVL 4

Author Comment

by:delphi3
ID: 6191182
Geo,
Super Job!! Thank you!!  
I  replaced the memo1 with stringlist (I am learning to use StrLists and need to practice)

I added a little more for specific actions:

procedure TForm1.Button1Click(Sender: TObject);
var
  EStr: string;
  StrList: TStringList;
  L, I: integer;
begin
  StrList := TStringList.Create;
  ExecDosAppOutRedirect('ipconfig.exe /all', SW_HIDE, true, 'c:\myip.txt');
  StrList.LoadFromFile('c:\myip.txt');
    // If there is no gateway address shown then don't do this
    //  else get  specific gateway address
  if StrList.Count < 16 then
    begin
    Edit1.Text := 'Not Conncected to Net';
  end
   else
   begin
    I := 0;
    EStr := '';
    L := length(StrList.Strings[26]); // for my interest the specific
                                                 //answer is on line 26 of the StrList
    while I < 15 do
    begin
      EStr := StrList.Strings[26][L - I] + EStr; // start from the end and compose bkwds
      inc(I);
    end;
    Edit1.Text := EStr;
  end;
  DeleteFile('c:\myip.txt');
  StrList.Free;
end;

procedure TForm1.Button2Click(Sender: TObject); // (if not connected to net error)
begin
  Application.Terminate;
end;


Thanks again.

Delphi3
 
0
 
LVL 5

Expert Comment

by:knowlton
ID: 6191255
delphi3:

I am glad you found your answer!  :)

Tom
0
 
LVL 17

Expert Comment

by:geobul
ID: 6191672
You are welcome

Regards, Geo
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now