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
Solved

Show ipconfig with a D4 program?

Posted on 2001-06-13
12
444 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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: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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

789 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