OpenURL and/or ShellExecute on Vista
-
My UI.openURL calls to launch an image are failing in Vista.
They work ok on XP, and they work OK in Vista for text files rather than images;
This works:
UI.openURL("c:/tmp/test3.txt")
This fails:
UI.openURL("c:/tmp/test2.jpg")
even though both files exist.
I am reading about problems with Windows ShellExecute in vista getting permission denied errors.
(I tried using Win32API and SkellExecute - but it has the same problems)I see in another post that TIG was having similar problems trying to load a PDF file.
Has anyone learned any more about it?
-
After some research, I discovered when I was calling ShellExecute from Win32API, that I was passing the action "open". Open does not exist imageds on Vista. (You can right click on an image to see that the two choice are Edit and Preview). When I change "open" to "" (blank), it worked, but UI.openURL() still does not work. I suspect that SketchUp has made the same mistake and implemented openURL() in such a way that it passes the verb "open".
-
ShellExecute API has open verb (see documentation). it has nothing to do with right click menu which can be modified to anything (e.g. mysuperduperopenfunctionthatdoesntwork)
you need to trace down the API to see what the real error is (wrong path, bad associations, no privileges, ...)
-
First try changing the default application that opens jpg's - I guess you'll have IE set... Another exe will probably open them. I think the Vista security craziness extends into stopping apps running in IE so web originating exe incursions are stopped, and it includes opening any file like a jpg that might contain hidden 'nastiness'...
The internet settings for IE could also be adjusted to see if that helps...
-
Perhaps the user can add any ShellExecute verbs they want, but in Vista, the default for images does not have an "open" verb.
Here is a right click on a text file.
Here is a right click on an image.
So when you issue an "open" on an image, ShellExecute fails.
If you leave out the verb, then both txt and jpg use the default (bold) action.
shell = Win32API.new("shell32","ShellExecute", ['L','P','P','P','P','L'], 'L' ) #<Win32API;0x5a8e290> #shell.call(handle, verb, file, params, folder, showCmd) nil shell.call(0, "open", "c;/docs/Apples.jpg", "", "", 1) 31 shell.call(0, "edit", "c;/docs/Apples.jpg", "", "", 1) 42 shell.call(0, "", "c;/docs/Apples.jpg", "", "", 1) 42
In the code above, "open" fails and returns 31 - ERROR_GEN_FAILURE
"edit" loads the image properly, and "" loads the image properly. -
I have open for images in my Vista
if you use "" it is the same as giving NULL to ShellExecute which takes in this order:
- the default one (the bold text),
- then the "open" verb
- then the first item in registry.
error 31 is "There is no application associated with the given file name extension" which in your case is true.
-
@al hart said:
Perhaps the user can add any ShellExecute verbs they want, but in Vista, the default for images does not have an "open" verb.
In my Vista jpgs DO happily have Open with the default[bold] right-click verb 'Open', listed after that is Edit, Print etc... However I do recall something messing up with Vista for me on some file-type, where the double-click on the icon stopped 'Open'ing the file is the associated app - much like you show... I fixed it by hacking around in the Registry and swapping Open/Edit around etc - can't remember what or where... Caused by installing some 3rd party app that I removed...On my Vista jpgs will open fine with UI.openURL(), whatever the jpg default app is set to, including IE, and they all show 'Open' as their default clicking action...
-
I'll have to look at my other Vista machines and see if they have open as a default.
Perhaps a Photo program I downloaded changed the settings.
(Or I have read that the setting may depend on your default Internet Browser)In Googleing around I see where others are having similar problems with Shell Execute in Vista.
I need a solution which will work for lots of users everywhere, with lots of different Windows settings.
What I did was to create a function to call UI.openURL, and then if it fails use ShellExecute with the NULL verb. This seems to work.
(I'm not sure why I call openURL first - just to be friendly to the SketchUp Ruby API I guess)def launch_file(sfile) trace("Launch; %s", sfile) # Try SketchUp call first if (UI.openURL(sfile)) return end#if # try shell_execute if openURL fails shell_execute(sfile) require 'Win32API' shell = Win32API.new("shell32","ShellExecute", ['L','P','P','P','P','L'], 'L' ) #shell.call(handle, verb, file, params, folder, showCmd) iret = shell.call(0, 0, sfile, 0, 0, 1) if (iret == 42) return true end#if do_error("Cannot Open file; '%s' - return value; %s", sfile, iret) return(false) end#def
Advertisement