7

I use ShellExecute to open files. On a single machine among 2000+ users I cannot open doc files. docx are opened with Wordpad.

Word 2010 is correctly installed and from explorer double cliicking on a word file opens word correctly, moreover the doc is showing with the correct icon in explorer. Note that all the other files work ok (like xls, xlsx, pdf, ...)

Does anyone know why? I checekd and "use this application to open files" it is checked.

In code I check the error and I know that the error message is

SE_ERR_ASSOCINCOMPLETE or SE_ERR_NOASSOC

(becuase in both cases I show an error "no appliaction is associated with the type of file", so i don't know which of the errors is there, I shuold debug at customer end to see it, but I don't think it is so important in this case).

Has anyone an idea? This is what I use to open the file:

ShellExecute(0, 'open', PWideChar(MyFilePath), '', '', SW_SHOWNORMAL);

Note: it looks to me some like problem is there in windows registry for this machine, it is a almost fresh windows 7 machine.

NOTE for who is voting for closing this question as Off Topic: it is in fact a question on WinAPI: why this api doesn't work as expected when from explorer it does? So this is not off topic, expecially winapi is in tags.

UnDiUdin
  • 14,924
  • 39
  • 151
  • 249
  • Regarding your edit, winapi is only in the tags because I edited them in and got rid of the unhelpful Delphi tag. But I think this is probably more of an issue with the particular machine than a coding issue, hence the off-topic, move to superuser close votes. – David Heffernan Jun 10 '11 at 19:13
  • @David, yes I know you retagged, but it was easier to me to say " expecially winapi is in tags" then " expecially winapi is in tags even if I originally didn't add it and it was done by an edit by David Heffeman". :) – UnDiUdin Jun 13 '11 at 07:55

1 Answers1

7

This is just a guess, but I suspect Explorer is using NULL where you have "open". This can trigger subtly different behavior if there's anything amiss in the user's registered file associations. For example, if there's a default verb other than "open".

Adrian McCarthy
  • 45,555
  • 16
  • 123
  • 175
  • Isn't it usually the other way around? – David Heffernan Jun 10 '11 at 19:54
  • 2
    @David: specifying `NULL` tells `ShellExecute()` to invoke the default registered verb, falling back to `"open"` if none exists, and falling back to the first found if `"open"` does not exist. Most legacy code used hard-coded `"open"` because that used to be the typical default verb. That is not as common nowadays, so it is better to use `NULL` now and let the OS decide which verb to invoke. – Remy Lebeau Jun 10 '11 at 21:00
  • It seems rather unlikely that Word hasn't registered the open verb – David Heffernan Jun 10 '11 at 22:26
  • 1
    Yes, it's unlikely. But the question says it's one machine out of 2000+. It's possible somebody mucked with the file associations on that one machine and messed things up, but not so much that Explorer can't find a default or fallback command. – Adrian McCarthy Jun 11 '11 at 14:05
  • 1
    Yes you were right. using nil instead of 'open' solved the problem. On that machine the error was SE_ERR_NOASSOC, for sure there was some mess with the Office installation. Thanks for your guess. – UnDiUdin Jun 13 '11 at 10:12