windows 如何使用默认程序从网络驱动器/路径打开文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6465828/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to open a file from network drive/path with default program?
提问by ZeissS
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.
从我的应用程序中,我想使用网络驱动器中的默认 Windows 程序打开文件(jpg、pdf、..)。我知道start
,但它似乎不适用于网络路径。
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.exe(P:\ 是网络驱动器):
cmd /c "start \server\path\to\image.jpg"
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.
更新:我发现了问题。请看我下面的回答。
回答by kunal
I tried these two commands:
我试过这两个命令:
- start Z:\SQLWriter.doc
- start \192.168.10.230\MyFolder\SQLWriter.doc
- 启动 Z:\SQLWriter.doc
- 开始\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
或者你可以通过这个链接:http: //www.codeguru.com/forum/showthread.php?t=302501
回答by Aleks G
I think the function you need is ShellExecute - it would look something like this:
我认为您需要的功能是 ShellExecute - 它看起来像这样:
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.
PS 我知道我应该将此作为评论发布,但还不能对所有帖子发表评论。
回答by ZeissS
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.
好的,我找到了问题所在。似乎 Windows 注册表有点混乱。如前所述,文本和文档等其他文件也可以使用,因此唯一的问题是 JPEG 文件。
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.
在 Windows 资源管理器中双击它们对它们来说效果很好,但使用该start
命令向我显示了上述弹出窗口。在这里选择一个程序并将其标记为永久解决了我的问题。进一步调用start
现在可以直接正确打开图像。