如何使用默认程序从网络驱动器/路径打开文件?

发布于 2024-11-16 21:16:14 字数 415 浏览 3 评论 0原文

从我的应用程序中,我想使用网络驱动器中的默认 Windows 程序打开文件(jpg、pdf、..)。我知道 start,但它似乎不适用于网络路径。

我尝试了以下命令,但我得到的只是 Windows 对话框,告诉我他不知道如何打开该文件以及我是否想使用网络服务来请求程序或手动选择。

从 cmd.exe(P:\ 是网络驱动器):

cmd /c“启动\server\path\to\image.jpg”

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

文件的路径是正确的,在资源管理器中单击它可以正常工作。

谢谢

更新:我发现了问题。请参阅下面我的回答。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寂寞陪衬 2024-11-23 21:16:14

我认为您需要的功能是 ShellExecute - 它看起来像这样:

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

PS 我知道我应该将此作为评论发布,但还不能对所有帖子发表评论。

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.

红焚 2024-11-23 21:16:14

我尝试了这两个命令:

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

这两个命令都运行良好。我没有收到任何错误消息。
如果您希望它启动,您可以使用它们。

 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)

或者您可以访问此链接: http://www.codeguru.com/forum /showthread.php?t=302501

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

旧人九事 2024-11-23 21:16:14

好的,我已经找到问题了。看来 Windows 注册表有点混乱。
正如之前所评论的,其他文件(例如文本和文档)也可以工作,因此唯一的问题是 JPEG 文件。

在 Windows 资源管理器中双击它们效果很好,但使用 start 命令会显示上述弹出窗口。在这里选择一个程序并将其标记为永久解决了我的问题。现在,进一步调用 start 可以正确地直接打开图像。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文