Highlighted
Absent Member.
Absent Member.
3040 views

[archive] calling a program by his extention

[Migrated content. Thread originally posted on 14 May 2003]

I am searching a way to have the path and the program that is related to the extention.

Ex.
123.DOC = C:\Program Files\Microsoft Office\Office10\WINDORD.EXE

OR

123.XLS = C:\Program Files\Microsoft Office\Office10\EXCEL.EXE

I now i can find in register this information but it is not what i am searching for!
0 Likes
15 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] calling a program by his extention

You need to use the FindExecutable() Windows API call.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] calling a program by his extention

Here is some sample code using the FindExecutableA Shell32.dll function:

77 WS-FILE PIC X(255) VALUE SPACES.
77 WS-DIRECTORY PIC X(255) VALUE SPACES.
77 WS-RESULT PIC X(255) VALUE SPACES.
77 WS-PROGRAM-PATH PIC X(255) VALUE SPACES.
77 WS-COMMAND-LINE PIC X(512) VALUE SPACES.
*Return value must be unsigned-long for win32.
01 RETURN-VALUE USAGE UNSIGNED-LONG.

MOVE "123.DOC" TO WS-FILE.
INSPECT WS-FILE REPLACING TRAILING SPACES BY NULLS.
MOVE "C:\MYDOCS" TO WS-DIRECTORY.
INSPECT WS-DIRECTORY REPLACING TRAILING SPACES BY NULLS.
INSPECT WS-RESULT REPLACING TRAILING SPACES BY NULLS.
* Call the WIN32 API.
SET ENVIRONMENT "DLL-CONVENTION" TO 1.
CALL "SHELL32.DLL".
CALL "FindExecutableA" USING
WS-FILE
WS-DIRECTORY
WS-PROGRAM-PATH
RETURNING RETURN-VALUE
ON EXCEPTION CONTINUE
NOT ON EXCEPTION
STRING WS-PROGRAM-PATH DELIMITED BY NULL,
" " DELIMITED BY SIZE
WS-FILE DELIMITED BY NULL
INTO WS-COMMAND-LINE.
CANCEL "SHELL32.DLL".
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] calling a program by his extention

It would be nice if Acucorp can do all the work for us. E.g. if the routine "C$SYSTEM" would be enhanced to with an option to start a program that is related to the extension.

I could really use this function, because we work with Thin Client and cannot call a windows .dll (yet).

But then again, support for calling windows DLL's with the Thin Client would also be nice, because our customers want to be able to make a printscreen and that is also possible via a DLL call (See forum thread Graphical print screen)

Does anyone else also wants this feature added to the C$SYSTEM routine or wants the Thin Client to be able to call Windows DLL's ?
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] calling a program by his extention

If you actually want to start the program and open the file, you should be able to just use the "start" command through C$SYSTEM.

For example, execute: start \path\abc.xls

This will start Excel (or whatever is associated with .xls) and load that file. "start" is a Windows command - you can type it at a Command Prompt or Start/Run also.

The original post just wanted the .exe path, not to actually start the .exe, so FindExecutable is needed in that case.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] calling a program by his extention

If I have the program path and the file's path contains spaces

e.g.
CALL "C$SYSTEM" USING "C:\Program Files\Microsoft Office\Office10\WINWORD.EXE C:\My files\test.doc"

The message I get is:
"The document name or path is not valid (C:\My)"

Can I open this file with "C$SYSTEM" ? I use ActiveX control now, but I would like to open it using "C$SYSTEM" routine
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] calling a program by his extention

You should wrap double quotes around the program path and the file path. So the call should look like this:

CALL "C$SYSTEM" USING '"C:\Program Files\Microsoft Office\Office10\WINWORD.EXE" "C:\my files\test.doc"'

Notice single quotes around the entire literal. Single quotes only needed for literal call, not for variable call.

So, the STRING statement in the FindExectuable() sample would change to this:

STRING '"' DELIMITED BY SIZE,
WS-PROGRAM-PATH DELIMITED BY NULL,
'"' DELIMITED BY SIZE,
" " DELIMITED BY SIZE,
'"' DELIMITED BY SIZE,
WS-FILE DELIMITED BY NULL,
'"' DELIMITED BY SIZE,
INTO WS-COMMAND-LINE

'"' is a double quote wrapped by two single quotes. You could also use hex equivalent of X"22" instead.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] calling a program by his extention

Thank you Danm. It works fine!
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] calling a program by his extention

Actually, thank you for pointing this out. I should have thought of this when I wrote the sample code. My production code has it in there.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] calling a program by his extention

Hi Administrator,

please send the following inforamtion to the User JoeD:

Hi JoeD,

you've answered:

I wrote an ActiveX control to do this. It's kind of clunky, but it works. I
wrote a control that lets me read or write files on the client. Transferring
binary data is tough - I am converting it to hex strings before writing it
to the control and then un-hexing it on the client in the control. That
doubles the transfer time.

It would be nice if this was in the thin client - one less control I have to
install on the client side.

My Question: Can you send me this Control and a sample Cobol-Program to use
this control ?

sincerly

Peter D?rrenb?cher-Alles
KISS GmbH Personalsysteme
Wellesweiler Strasse 95
66538 Neunkirchen
Deutschland
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] calling a program by his extention

Originally posted by JoeD
If you actually want to start the program and open the file, you should be able to just use the "start" command through C$SYSTEM.

For example, execute: start \path\abc.xls

This will start Excel (or whatever is associated with .xls) and load that file. "start" is a Windows command - you can type it at a Command Prompt or Start/Run also.



Thanks for the tip. I think start is not an executable, but a shell builtin. I have to start it as follows (using thin client):

           add csys-desktop, csys-async, csys-compatibility,
               csys-shell, csys-hidden
               giving csys-flags
           call "c$system" using "start abc.xls" csys-flags


csys-shell causes the command to run in a command shell and csys-hidden causes the command line window to stay invisible. When you don't specify csys-hidden an annoying command line window appears just before excel is executed.

Tip: This also works with URL's; when you specify 'start mailto:support@acucorp.com' a new mail message to support@acucorp.com is generated.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] calling a program by his extention

I've found start to be problematic when there are spaces in the file path. Even when I wrap double quotes around the file path. Using the short file path seems to work, but this may not always be available to you and may require another API call to resolve long path to a short path. Has anyone got around this problem with start?

does not work:
start c:\my file\test.txt
start "c:\my file\test.txt"

does work:
start c:\myfile~1\test.txt

This is on win xp, haven't tried other win o/s. Any ideas?
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.