Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 464
  • Last Modified:

Show ipconfig with a D4 program?

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
delphi3
Asked:
delphi3
  • 4
  • 3
  • 3
  • +1
1 Solution
 
Tom KnowltonWeb developerCommented:
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
 
delphi3Author Commented:
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
 
Tom KnowltonWeb developerCommented:
It would be _default.pif.

I meant to post as a comment, not an answer.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
delphi3Author Commented:
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
 
Mohammed NasmanSoftware DeveloperCommented:
Hello

  Try this also

winexec('command.com /c ipconfig', sw_shownormal);
0
 
geobulCommented:
Hi,
Just a notice: there is 'WINIPCFG.EXE' in windows system directory which is windows version of ipconfig.

Regards, Geo
0
 
Mohammed NasmanSoftware DeveloperCommented:
geobul, you will not find winipcfg in win2k, ipconfig come with win2k instead of it, winipcfg come with win 9x

Mohammed
0
 
geobulCommented:
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
 
delphi3Author Commented:
Knowlton,
As I said earlier I need something that does not just blink.
Sorry for the reject.

Delphi3
0
 
delphi3Author Commented:
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
 
Tom KnowltonWeb developerCommented:
delphi3:

I am glad you found your answer!  :)

Tom
0
 
geobulCommented:
You are welcome

Regards, Geo
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now