Delphi and Kylix

Moderators: pritaeas
Number of threads: 7264
Number of posts: 19073

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
ShellExecute Problem!! Posted by Kapetanios on 29 Sept 2006 at 2:27 PM
Hi!
When i try to open a URL with a certain web browser using
ShellExecute like this:

ShellExecute(Handle,'open',PChar(BrowserExeFile),PChar(URL),nil,SW_SHOWNORMAL);

it fails! The web browser opens the home page instead of the URL!

When i try to open a document (.txt or .rtf of .doc) with Wordpad or Word this way:

ShellExecute(Handle,'open',PChar(WordPad),PChar(file),nil,SW_SHOWNORMAL);

it fails to find the specified file. This happens only when the path to the file includes a folder with a name including spaces. For example,
if file='C:\MyFolder\Poetry.doc' then there is no problem. But if
file='C:\My Folder\.doc' then Wordpad opens with this message: "C:\My Cannot find this file".

Any idea why these strange thinks happen?

Note: Ι use Delphi6 and Fully qualified filenames.
Report
Re: ShellExecute Problem!! Posted by zibadian on 29 Sept 2006 at 5:12 PM
: Hi!
: When i try to open a URL with a certain web browser using
: ShellExecute like this:
:
: ShellExecute(Handle,'open',PChar(BrowserExeFile),PChar(URL),nil,SW_SHOWNORMAL);
:
: it fails! The web browser opens the home page instead of the URL!
:
: When i try to open a document (.txt or .rtf of .doc) with Wordpad or Word this way:
:
: ShellExecute(Handle,'open',PChar(WordPad),PChar(file),nil,SW_SHOWNORMAL);
:
: it fails to find the specified file. This happens only when the path to the file includes a folder with a name including spaces. For example,
: if file='C:\MyFolder\Poetry.doc' then there is no problem. But if
: file='C:\My Folder\.doc' then Wordpad opens with this message: "C:\My Cannot find this file".
:
: Any idea why these strange thinks happen?
:
: Note: Ι use Delphi6 and Fully qualified filenames.
:
The reason, why the program cannot open c:\my folder\.doc, is that that's an illegal filename.
As for the URL, it is easier to use the URL as the executable. That way it will load it into the default browser. Sometimes browsers need additional paramters to link to an URL. See the documentation of the browser if that's the case.
Report
Re: ShellExecute Problem!! Posted by Kapetanios on 29 Sept 2006 at 10:39 PM
The reason, why the program cannot open c:\my folder\.doc, is that that's an illegal filename.
: As for the URL, it is easier to use the URL as the executable. That way it will load it into the default browser. Sometimes browsers need additional paramters to link to an URL. See the documentation of the browser if that's the case.


1) Oups!! Sorry! Type mistake! What i try and fails is file='C:\My Folder\Poetry.doc' and not file='C:\My Folder\.doc' and, so ,it is a legal name but it doesn't work. Notepad works fine with this parameter but Wordpad and Word seem to have problem with this filepath that contains a space.

2) Hmm...i will check the parameters needed for the browser!


Report
Re: ShellExecute Problem!! Posted by zibadian on 29 Sept 2006 at 10:53 PM
: The reason, why the program cannot open c:\my folder\.doc, is that that's an illegal filename.
: : As for the URL, it is easier to use the URL as the executable. That way it will load it into the default browser. Sometimes browsers need additional paramters to link to an URL. See the documentation of the browser if that's the case.
:
:
: 1) Oups!! Sorry! Type mistake! What i try and fails is file='C:\My Folder\Poetry.doc' and not file='C:\My Folder\.doc' and, so ,it is a legal name but it doesn't work. Notepad works fine with this parameter but Wordpad and Word seem to have problem with this filepath that contains a space.
:
: 2) Hmm...i will check the parameters needed for the browser!
:
:
:
Place the filename in quotes. That makes of a filepath with spaces a single commandline parameter: "C:\My Folder\Poetry.doc"
Report
Re: ShellExecute Problem!! Posted by Kapetanios on 29 Sept 2006 at 11:40 PM
: :
: Place the filename in quotes. That makes of a filepath with spaces a single commandline parameter: "C:\My Folder\Poetry.doc"
:


Yeap! It worked!! )) Thank you!

What hasn't work is opening the web browser with the url as a parameter.
While "C:\.....\firefox.exe www.yahoo.com" work through the command line,
the :
ShellExecute(handle,'open',PChar(BrowserExePath),PChar(URL),nil,SW_SHOWNORMAL);
doesn't work!

I tried to make it throught WinExec, too, but the result was the same.
Report
Re: ShellExecute Problem!! Posted by zibadian on 30 Sept 2006 at 2:59 AM
: : :
: : Place the filename in quotes. That makes of a filepath with spaces a single commandline parameter: "C:\My Folder\Poetry.doc"
: :
:
:
: Yeap! It worked!! )) Thank you!
:
: What hasn't work is opening the web browser with the url as a parameter.
: While "C:\.....\firefox.exe www.yahoo.com" work through the command line,
: the :
: ShellExecute(handle,'open',PChar(BrowserExePath),PChar(URL),nil,SW_SHOWNORMAL);
: doesn't work!
:
: I tried to make it throught WinExec, too, but the result was the same.
:
Try using this:
ShellExecute(handle, nil, PChar(URL), nil , nil, SW_SHOWNORMAL);

That should work.

Report
Re: ShellExecute Problem!! Posted by Kapetanios on 30 Sept 2006 at 5:21 AM
: :
: Try using this:
:
: ShellExecute(handle, nil, PChar(URL), nil , nil, SW_SHOWNORMAL);
: 

: That should work.
:
:
Of course!! I know!
But it opens the default browser.
What am i trying to do is open a non-default browser at a certain URL.
I can open a certain URL, i can open a non-default browser but i cannot
do both in one, because i cannot pass parameters to the browser. I know it must be a way. When i right-click an html file and choose open with... choosing a non-default browser...it works!!! When i do that through command line, it works!! I don't know. It should be a way that involves window APIs.
Whatever, let's forget it for the moment. If i find something a will
make a new post here.
Report
Re: ShellExecute Problem!! Posted by zibadian on 30 Sept 2006 at 5:37 AM
: : :
: : Try using this:
: :
: : ShellExecute(handle, nil, PChar(URL), nil , nil, SW_SHOWNORMAL);
: : 

: : That should work.
: :
: :
: Of course!! I know!
: But it opens the default browser.
: What am i trying to do is open a non-default browser at a certain URL.
: I can open a certain URL, i can open a non-default browser but i cannot
: do both in one, because i cannot pass parameters to the browser. I know it must be a way. When i right-click an html file and choose open with... choosing a non-default browser...it works!!! When i do that through command line, it works!! I don't know. It should be a way that involves window APIs.
: Whatever, let's forget it for the moment. If i find something a will
: make a new post here.
:
This works:
  ShellExecute(handle, nil, PChar(MyBrowser), PChar(URL), nil, SW_SHOWNORMAL);

Notice that I didn't include the operation.
Report
Re: ShellExecute Problem!! Posted by Kapetanios on 30 Sept 2006 at 6:34 AM
: :
: This works:
:
:   ShellExecute(handle, nil, PChar(MyBrowser), PChar(URL), nil, SW_SHOWNORMAL);
: 

: Notice that I didn't include the operation.
:

Hhmmm! Yes, it works!! You made it!

So, this means that "open" prevents me pass parameters to some applications, like the browser?

Because it doesn't prevent me from passing parameters to notepad,wordpad or Word.

So people, be aware of that and two more thing when you use ShellExecute:

1) When you don't give the application path or the url through '.....' but through a string variable, a constant or Edit1.Text (or something similar) you should convert it through PChar function.

2) If the filepath is given through a string that contains spaces you may have problem. Make sure that you put the string between "".

3) Don't forget to declare "Uses ShellAPI;"

Thanks for your help!



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.