Solved

Shellexecute doesn't work

Posted on 2004-08-02
6
547 Views
Last Modified: 2010-04-04
I'm trying to execute
net send 10.10.10.10 Hi
and i tried

var stripmsg,Strcomando:String;

strcomando:=' send '+StrIPMsg+'XXX:ccc';
     ShellExecute(0,
     nil,
     PChar('net'),
     PChar(Strcomando),
     nil,
     SW_HIDE);

It doesn't work......
it just work like that...


ShellExecute(0,nil,PChar('net'),PChar(' send 10.1.1.24 la'),nil,SW_HIDE);

I mean....Am I not enabled to send a Strinf as a Pchar?
0
Comment
Question by:Iamme
6 Comments
 
LVL 7

Expert Comment

by:LRHGuy
ID: 11699454
This worked for me:

var
  stripmsg,Strcomando:String;
  Dir:array[0..144] of Char;
  Pgm:array[0..255] of char;
begin
  GetWindowsDirectory(Dir, 144);
  StrPCopy(Pgm,StrPas(Dir)+'\net.exe');

strcomando:='send '+StrIPMsg+'XXX:ccc';
{strcomando:='use i: \\computer-1\c';}
     ShellExecute(0,
     '',
     Pgm,
     PChar(Strcomando),
     nil,
     SW_HIDE);
end;

Although, "send" isn't a command the my "net" understands. It did process the "use" command fine though. Thr trick is telling shellexecute where to find the "net" command.

Hope that helps!
Larry
0
 
LVL 7

Expert Comment

by:LRHGuy
ID: 11699459
Sorry about the "typos" ... sometimes I type too fast!

Larry
0
 
LVL 6

Expert Comment

by:gwalkeriq
ID: 11699531
I think you will find that the problem in not ShellExecute, but the net send command itself.

For example, try this click event, and I think you should at least see the new view command flicker past quickly.

procedure TForm1.Button1Click(Sender: TObject);
var
  cmd: string;
begin
  cmd := 'view';
  ShellExecute(0, nil, pchar('net'), pchar(cmd), nil, sw_show);
end;

If you run the net send command by hand, I suspect you will see that it is failing.

For example, on my network:

C:>ping 192.168

Pinging 192.168.1.24 with 32 bytes of data:

Reply from 192.168.1.24: bytes=32 time<1ms TTL=128
Reply from 192.168.1.24: bytes=32 time<1ms TTL=128

--- But, attempt a message to the same address and it fails ----

C:\>net send 192.168.1.24 "Hello world"
An error occurred while sending a message to 192.168.1.24.

The message alias could not be found on the network.

I suspect you will find you have a similar problem.  Test from the C: prompt before you try to debug from within your program. Since you are using SW_HIDE, you can't even see a flicker with an error message.

0
Technology Partners: 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!

 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 11700900
Hello

  Try to use NetMessageBufferSend API for the same

look at my comment in this Paq for the sample
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20647390.html
0
 
LVL 1

Expert Comment

by:dragontron3k
ID: 11701935
Hi.

I had this problem as well. Don't pass net as the program to execute, but as the first parameter. This modification of your code should work:

strcomando:=' send '+StrIPMsg+'XXX:ccc';
     ShellExecute(0,
     nil,
     PChar(''),
     PChar('net ' + Strcomando),
     nil,
     SW_HIDE);
0
 
LVL 1

Accepted Solution

by:
dragontron3k earned 100 total points
ID: 11702054
Or, if you copied your question text directly from your source code, the problem might be that you forgot a space.

Where StrIPMsg = '10.1.1.24'

' send '+StrIPMsg+'XXX:ccc' will result in ' send 10.1.1.24XXX:ccc' instead of ' send 10.1.1.24 XXX:ccc'

Hope this or the previous helps.
0

Featured Post

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

735 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