Windows Programmer
Windows Programmer

Reputation: 103

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.

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.

I can not give the default handler application path, Is there any way to open files directly without specifying the Handler Application Path ?

Upvotes: 0

Views: 384

Answers (1)

Adriano Repetti
Adriano Repetti

Reputation: 67090

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.

If you know which application you want to use then search it in known applications (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 /c MyFile.txt

In code (just an example...):

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

Upvotes: 1

Related Questions