简体   繁体   English

打开.doc文件而不提供其处理程序应用程序C ++的路径

[英]Open .doc file without providing the path of its handler application C++

I need to open PDF and DOC files within my C++ project, the only limitation I have I can not use ShellExecute and WinExeute for opening extension files. 我需要在C ++项目中打开PDF和DOC文件,唯一的限制是我不能使用ShellExecute和WinExeute打开扩展文件。

Now, I tried to open the files with WMI queries and OpenProcess() , but both these procedures require the Handler application path along with the path of DOC/PDF file. 现在,我尝试使用WMI查询和OpenProcess()打开文件,但是这两个过程都需要Handler应用程序路径以及DOC / PDF文件的路径。

I can not give the default handler application path, Is there any way to open files directly without specifying the Handler Application Path ? 我无法提供默认的处理程序应用程序路径,是否可以在不指定处理程序应用程序路径的情况下直接打开文件?

You can resolve which application is associated with file you need to open. 您可以确定哪个应用程序与您需要打开的文件相关联。 A start point here and here . 这里这里的起点。 It may be tricky because of various details you may need to take into account but it's what ShellExecute does. 由于可能需要考虑各种细节,因此这可能很棘手,但这是ShellExecute要做的。

If you know which application you want to use then search it in known applications ( HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths ). 如果您知道要使用哪个应用程序,则在已知的应用程序HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths )中进行搜索。 This is useful only if you know which file type you're handling and which application you want to use. 仅当您知道要处理的文件类型和要使用的应用程序时,此功能才有用。

A more easy method may be to execute cmd.exe , you won't call ShellExecute and it'll do the job for you (executing default verb): 一个更简单的方法可能是执行cmd.exe ,您不会调用ShellExecute ,而是会为您完成这项工作(执行默认动词):

cmd /c MyFile.txt

In code (just an example...): 在代码中(仅作为示例...):

CreateProcess("cmd.exe",
        "/c c:\\MyFile.txt",
        NULL,
        NULL,
        FALSE,
        0,
        NULL,
        NULL,
        &startupInfo,
        &processInformation);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM