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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A MS workaround that I dont understand! 1

Status
Not open for further replies.

elziko

Programmer
Nov 7, 2000
486
GB
I have been following a thread in this forum about getting the executable for a file (ie. what application opens a particular file type). This API function (FindExecuatble) does not support long filenames stored in the registry unless they are surround by quotation marks. But when Access is installed it does not surround its long filename with quotation marks. In the MS Knowledgebase they offer a work around but I dont really understand how to implement it:


Has anyone tried this? Does anyone understand this?

Many Thanks,

elziko
 
Elziko -

What the workaround is that Microsoft describes is a "cheat" for C/C++ programmers.

What happens during the problem is the API call truncates the file path at the first space it encounters, replacing the space with a hex &H0 character. Their workaround says that if you suspect/know that the path should be longer, you can change that position back to a space, which (might) reveal the rest of the path. This might be possible in VB, but it's really dangerous. If you change the null character to a space when you're _not_ supposed to, then when you access the string you may or may not get an access violation, depending on how long it takes VB to find a terminating null character (&h0). Since this terminating null may or may not be in your memory space, you'll get variable results.

Here's a suggestion:
Instead of using the FindExecutable API call, do some registry queries yourself.

Look up the default value under HKEYROOT for ".xls". On my system this says "Excel.Sheet.8".

Now look up "Excel.Sheet.8" under HKEYROOT, and look at the shell\Open\command key under it. The default value on my system says:

[tab]"C:\Program Files\Microsoft Office\Office\EXCEL.EXE" /e

Strip the option off the end (if any), and you should have the path.

Chip H.
 
Thanks for taking a look at that.

Mmmm, it does sound dangerous. Maybe I want try that.

Yeah I thought of doing a bit of a wild registry goose chase as you have suggested but was hoping I wouldn't have to. At the moment I've got a "find your executable" prompt in my app. Not ideal. Maybe I will write my own "ReallyFindExecutable" function when I have more time;-)

Cheers,

elziko
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top