Discussion:
API FindExecutable
(too old to reply)
Ahmed Martens
2015-02-11 15:24:26 UTC
Permalink
Hallo Folks,

is it possible to use the API-Function 'FindExecutable' to find
assoziate exe in VBSript?

for example: *.xlsx -> Microsoft Excel

I will need the full path of the exe.

Thanks for all.

Gruß Ahmed
--
Antworten bitte nur in der Newsgroup.
Mayayana
2015-02-11 16:33:42 UTC
Permalink
You can't use API calls in VBS because they
require speficic data types and access to memory
locations. But you can do the equivalent in many
cases. In this case you can just do what
FindExecutable does:

- Read the Registry key default value in HKCR\.xlsx
- That should be a string like "Xlsx File"
- Read the Registry key under HKCR\Xlsx File
There should be a series of keys like so:

HKCR\Xlsx File\shell\open\command\

The default value there is the path to the
executable, assuming the file extension is
registered.
There are a couple of catches: Sometimes
the path will contain something like %system root%,
which needs to be translated. Also, WScript.Shell,
the official way to access the Registry, is not
very dependable. More dependable is to use WMI,
but that's also very messy. See if the simple way
works for what you need:

Dim SH, s, s2
Set SH = CreateObject("WScript.Shell")
s = SH.RegRead("HKCR\.txt\")
s2 = SH.RegRead("HKCR\" & s & "\shell\open\command\")
s2 = SH.ExpandEnvironmentStrings(s2)
MsgBox s2
Set SH = Nothing

That should display the path to Notepad. Notice
that it also probably has "%1" at the end. It may
also have other parameters. So the last step in
returning the executable path is to find the last \
and then strip off at the next space:

Pt1 = Instrrev(s2, "\")
Pt2 = InStr(Pt1, s2, " ")
If Pt2 > 0 Then s2 = Left(s2, (Pt2 - 1))
MsgBox s2
Ahmed Martens
2015-02-11 18:00:55 UTC
Permalink
Hallo Mayayana,

thanks for your help.
I will testing your solution.

Gruß Ahmed
--
Antworten bitte nur in der Newsgroup
Windows 7 64bit Home Premium
Office Prof. 2010
Mayayana
2015-02-11 18:47:29 UTC
Permalink
| I will testing your solution.
|

It should work OK because you're just reading
simple strings, but if you have any trouble you
can try this WMI Registry class:

http://www.jsware.net/jsware/scrfiles.php5#classpk

In the download there's a Registry class that uses
WMI methods. The class can just be pasted into your
script and used as an object. (Note that the WMI
service must be running for this method. It runs by
default but may be disabled on some machines.)

Loading...