Solved

Shellexecute doesn't work

Posted on 2004-08-02
6
550 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
[X]
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
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
Independent Software Vendors: 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

691 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