Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Execute External Program w/o Path 1

Status
Not open for further replies.

taysys

Programmer
Dec 7, 2001
41
US
I would like to execute Adobe Acrobat Reader for user of a program but I don't know the full path of the program. It could be in different directories depending on the version.

I have tried Winexec but it needs the full path. Any suggestions... thanks.

Bob Taylor
 
Hi
If you try to open a PDF file, Acrobat Reader will launch automatically - might be better to get the user to launch the target file rather than the Reader.

Hope this helps
Keith
 
Bob,

It sounds like a case for using ShellExecute, an API call.

If you want to use this, you need to declare it first. This is the actual code I use:

Code:
DECLARE INTEGER ShellExecute IN Shell32.DLL INTEGER hndwin,STRING cAction,STRING cFileName,STRING cParams,STRING cDir,INTEGER xShowWin

You can then use it to open any file that is registered in Windows such as .doc .xls .pdf .txt and so on. It checks with Windows to find the registered path for the program to run the file type you specify. You can also use it to open web pages using the default browser.

You call it as follows:

Code:
=ShellExecute(0,"open","[URL unfurl="true"]http://10.0.0.1/intranet/top.htm","","",1)[/URL]

Notice that the second parameter is the word open in quotes and the second parameters is the filename (or web address) again in quotes. You can replace open with all associated actions for a filetype such as print.

I can't remember what the other parameters are for, but you might find some help on this function on the Universal Thread.

Hope that helps, I use it a fair bit and have never had a problem.

Stewart
 
Webpager... thanks but StewartUK's response was exactly what I needed.

StewartUK... Thank you, the format and use of the "ShellExec" was what I was looking for. This works perfectly!

Bob Taylor
 
Here follows another example of the versatility of ShellExecute().

Windows Explorer is called, the start folder being determined by the variable lcFolder

LOCAL lcFolder

DECLARE INTEGER ShellExecute IN SHELL32.dll ;
[tab]INTEGER nWinHandle,;
[tab]STRING cOperation,;
[tab]STRING cFileName,;
[tab]STRING cParameters,;
[tab]STRING cDirectory,;
[tab]INTEGER nShowWindow

*!* Retrieve the main VFP window handle (this handle is used by ShellExecute)

DECLARE INTEGER FindWindow IN WIN32API;
[tab]STRING cNull,;
[tab]STRING cWinName

IF !EOF([TEMPFILE])
[tab]lcFolder = JUSTPATH(TEMPFILE.filename)
ELSE
[tab]lcFolder = [C:\]
ENDI

lnResult = ShellExecute(FindWindow(0,_SCREEN.caption),;
[tab][Explore],;
[tab]lcFolder,;
[tab][],;
[tab][],;
[tab]1)

**Error messages if the return value is < 32
IF lnResult < 32
[tab]DO CASE
[tab]CASE lnResult = 2
[tab][tab]lcText = [Invalid association or URL]
[tab]CASE lnResult = 31
[tab][tab]lcText = [The file type has no associated application]
[tab]CASE lnResult = 29
[tab][tab]lcText = [Unable to initialize the application]
[tab]CASE lnResult = 30
[tab][tab]lcText = [The application is already open]
[tab]ENDCASE
[tab]MESSAGEBOX(lcText,;
[tab][tab]0 + 64 + 0,;
[tab][tab][File error])
ENDIF

HTH

Chris :)
 
Chris,

Going on from your example, which is pretty tricky if I may say so, you might be interested to know that in VFP7, the VFP Window handle is now a property of _SCREEN which should simplify some things.

I remember you posting a reply to a message I posted about purchasing VFP7 in the UK. Did you ever find somewhere to get it from? I ended up buying mine from
HTH

Stewart
 
Stewart

I expect you gathered that the error messages in the last but one post are only examples of generic error messages relating to CreateProcess() and are not specific to this use of it.

Thanks for the info on sourcing VFP7 - I'm waiting for a serious service pack to emerge before taking the plunge!

Not convinced the water's warm enough yet. :-(

Chris :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top