Solved

Show ipconfig with a D4 program?

Posted on 2001-06-13
12
440 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: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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
calling procedure inside activexForm from secondform 1 232
code issue 8 100
Connection between libmysql.dll and MySQL Versions 7 87
PHP preg_replace code convert to Delphi 14 35
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

896 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

14 Experts available now in Live!

Get 1:1 Help Now