Solved

Show ipconfig with a D4 program?

Posted on 2001-06-13
12
453 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 5

Expert Comment

by:Tom 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:Tom Knowlton
ID: 6189313
It would be _default.pif.

I meant to post as a comment, not an answer.
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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:Mohammed Nasman
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
 
LVL 22

Expert Comment

by:Mohammed Nasman
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:Tom 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month9 days, 4 hours left to enroll

617 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