1
votes

from my application I want to open files (jpg, pdf, ..) with the default windows-program from network drives. I know start, but it doesn't seem to work for network paths.

I tried the following commands, but all I get is the windows dialog telling me that he doesn't know how to open that file and whether I want to use a web-service to ask for a programm or choose manually.

From cmd.exe (P:\ is a network drive):

cmd /c "start \server\path\to\image.jpg"

> cmd /c "start P:\path\to\image.jpg"

The path to the file is correct and clicking on it in the explorer works fine.

Thanks

UPDATE: I found the problem. See my answer below.

3
I think you should be using one of the shell functions, not cmd.exe / start.exe, but I'm not sure which one. ShellExecuteEx? I'd have thought there was something simpler. - Rup

3 Answers

2
votes

I think the function you need is ShellExecute - it would look something like this:

ShellExecute(ParentWindowHandl, "open", "Z:\SQLWriter.doc", NULL, SW_SHOWNORMAL);

P.S. I know I should post this as comment, but can't comment on all posts yet.

2
votes

I tried these two commands:

  1. start Z:\SQLWriter.doc
  2. start \192.168.10.230\MyFolder\SQLWriter.doc

Both the commands worked perfectly. I didn't get any error messages. You can use these if you want it to launch.

 SHELLEXECUTEINFO ExecuteInfo;

memset(&ExecuteInfo, 0, sizeof(ExecuteInfo));

ExecuteInfo.cbSize       = sizeof(ExecuteInfo);
ExecuteInfo.fMask        = 0;                
ExecuteInfo.hwnd         = 0;                
ExecuteInfo.lpVerb       = "open";                      // Operation to perform
ExecuteInfo.lpFile       = "cmd.exe";  // Application name
ExecuteInfo.lpParameters = "start P:\Myfile.jpg";           // Additional parameters
ExecuteInfo.lpDirectory  = 0;                           // Default directory
ExecuteInfo.nShow        = SW_SHOW;
ExecuteInfo.hInstApp     = 0;

if(ShellExecuteEx(&ExecuteInfo) == FALSE)

Or you can go through this link: http://www.codeguru.com/forum/showthread.php?t=302501

1
votes

Ok, I have found the problem. Seems like the windows registry was a bit confused. As commented before, other files like text and doc work, so the only problem was JPEG files.

Double Clicking them in the Windows Explorer worked fine for them, but using the start command showed me the popup described above. Selecting a program here once and marking it as permanent resolved my problem. Further calls with start now correctly open the image directly.