Solved

ShellExecute to a Shortcut - How to

Posted on 2007-12-05
17
997 Views
Last Modified: 2012-06-27
Hi experts,

I need to know how to ShellExecute to a Shortcut ?

Anyone know how?

Thanks

ST3VO
0
Comment
Question by:ST3VO
  • 6
  • 6
  • 5
17 Comments
 
LVL 18

Assisted Solution

by:Johnjces
Johnjces earned 250 total points
ID: 20414690
if shellexecute(handle, nil, Pchar('C:\Documents and Settings\johns\Desktop\fileZilla.lnk'), nil, nil, SW_SHOW) < 32 then
    ShowMessage('Unable to open file');

or...

if shellexecute(handle, nil, Pchar('C:\Program Files\JCITS Systems\CDLibrary\THE CD Library.url'), nil, nil, SW_SHOW) < 32 then
    ShowMessage('Unable to open file');

if an URL


if that is the kind of shortcut you are seeking. A shortcut on my desktop. Could be a shortcut put anywhere. The .lnk is always hidden.

John
0
 
LVL 19

Accepted Solution

by:
MerijnB earned 250 total points
ID: 20414711
see this example:
procedure TForm3.Button1Click(Sender: TObject);

begin

 ShellExecute(0, nil, 'c:\notepad.lnk', nil, nil, SW_SHOWNORMAL);

end;

Open in new window

0
 
LVL 18

Expert Comment

by:Johnjces
ID: 20414764
MerijnB,

That's what I have.... Other than you have a 0 handle.

John
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 20414783
sorry, hadn't seen your comment when I posted mine
0
 
LVL 18

Expert Comment

by:Johnjces
ID: 20414865
As a side note, if you want to create an URL shortcut make a text file with a .url extension and write:

[InternetShortcut]
URL=http://delphi.about.com

Save it anywhere.

John
0
 

Author Comment

by:ST3VO
ID: 20416097
Hmmm.....In my situation none seem to work.

I'll explain better.

I've written an active Form Control which is deployed in a web page.
OnClick it uses Shellexecute to Run an Application.
The Application actually does run BUT this application is a control application which itself shellexecutes other .exe (apps).

By using Shellexecute directly to run the .exe, it will run the exe but this opened .exe will not run other .exe from it.

So, I decided to try via a Shortcut, which it why I'm asking here.

The problem is that the shortcut don't run the .exe from the Active Form.

Any ideas of how to solve this issue please?

Thanks

ST3VO
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 20417836
I think this is a security precaution to prevent you from running something from a webpage.
0
 

Author Comment

by:ST3VO
ID: 20418225
I can actually get it to run!

This with the case:

1 -----Active Form
              |___Loads App1.exe (works ok)
                                       |___Load external exe (Doesn't work)

So, it's not that the Active Form doesn't run the .exe ....It's the .exe that it loads that doesn't load the external app from itself.

p.s: This works fine if I load the application directly bypassing the Active Form!

0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 19

Expert Comment

by:MerijnB
ID: 20418274
Do you get any errors from app1.exe?
If not, build in some logging so you can see where things are going wrong.
and why can't you start external.exe directly?
0
 

Author Comment

by:ST3VO
ID: 20418320
No...no errors at all....the app just doesn't load!

I'll give it a go!
0
 
LVL 18

Expert Comment

by:Johnjces
ID: 20419732
St3vo and EE Moderator,

I do not mean to complain. But...

This question has gone from a fairly simple,

"I need to know how to ShellExecute to a Shortcut ?"

to a second and much broader question;

"I've written an active Form Control which is deployed in a web page. OnClick it uses Shellexecute to Run an Application. The Application actually does run BUT this application is a control application which itself shellexecutes other .exe (apps). By using Shellexecute directly to run the .exe, it will run the exe but this opened .exe will not run other .exe from it. So, I decided to try via a Shortcut, which it why I'm asking here. The problem is that the shortcut don't run the .exe from the Active Form."

I do not believe this is proper and am asking the moderator and you to rethink this question.

Close it and ask again properly and in its entire context, or something.

Open to discussion from other experts as well if I am all wet, wrong, or too complaining etc.!

John
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 20419783
I tend to doubt.

For one part I agree with you, on the other hand, ST3VO is always _very_ generous with his points (he actually _always_ gives 500 points) even for very simple questions.

If this question was awarded with < 100 points I'd agree, now I'm not sure...
0
 

Author Comment

by:ST3VO
ID: 20420141
Thanks MerijnB for your comment! It's my pleasure, because you guys are always there to help!

Any 95% of the time I need an answer ASAP and your guys are giving me your knowledge and time!

I wish I was at least a decent programmer but I am not, although I DO try my best to learn things as quick as possible! I learn every day with the help you your guys!

About this question, Yes, I agree that I didn't explain myself properly. This is because I thought that executing a shortcut would solve the problem but it hasn't.

I agree that all I asked is to perform a shellexecute on a .lnk file, so if you wan't just assign those points and open another question!

Thanks again and sorry about that!

ST3VO
0
 
LVL 18

Expert Comment

by:Johnjces
ID: 20420345
It's not that I desire the points nor is it about the points... really!

It's about being full and open with the problem you are trying to solve. I realize at times we believe that there is a simple solution but it does not turn out to be simple.

I really like to help and provide as much information that I know. But don't we deserve all the information from the "gitgo?

But, IMHO (for what it is worth), questions should not grow whether you assign 50 points or 1000 points. If the question is answered and answered correctly, then it should be closed.

If the question grows into something completely different like executing an application from an application from a link then I believe that is entirely separate and a new question. I believe that in most your questions (from what I have read), you should supply as much information to those that might help you at the very beginning. Read through some posts and see how they have grown?

Show some snippets of what you've done and where the problem is. Is simply closing and reopening an ADOQuery going to solve your problem?

I could be really off base. I am not flaming, but I too am trying to learn. About this forum and more about Delphi.

Again... my opinion and how I read the rules.

My rant and 2 cents.

Thanks and sorry if I offended someone or if they took this the wrong way!

John
0
 
LVL 18

Expert Comment

by:Johnjces
ID: 20420520
Last of my 2 cents....

Would a batch file work for you?

Create a batch .bat file with the path and executable contained therein. Try and create a link to the batch file and see if that works.

John
0
 

Author Closing Comment

by:ST3VO
ID: 31413174
Here are the points! Question closed! Yes...the asked question a question and got an answer but as MerijnB said I am usualy very generous with the points and the gradings because I appreciate your time and effort and a bit of flexibility would have been appreciated considering the number of questions I ask and the grades I give.
But never mind! I'll be more careful next time!
Thanks

ST3VO
0
 

Author Comment

by:ST3VO
ID: 20420553
OK, I'll try ...thanks!!!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

10 Experts available now in Live!

Get 1:1 Help Now