Associate PDF file with browser

Associate PDF file with browser

Postby Ari » Sun May 28, 2023 8:18 pm

Hello,

I searched and did not find a way to associate a PDF file with standard internet browsing, via programming,

Anybody know ?
Thanks,
Ari

FWH 2212 - Harbour 3.2.0 - Embarcadero 7.43 - MySQL
São Paulo - SP - Brasil
www.sisrev.com.br
User avatar
Ari
 
Posts: 228
Joined: Fri Feb 03, 2006 4:21 pm
Location: São Paulo, SP - Brazil

Re: Associate PDF file with browser

Postby Antonio Linares » Mon May 29, 2023 10:58 am

Dear Ari,

chatGPT answer:
You can use the Windows Registry to associate file extensions with default programs. Specifically, you'll need to modify the registry entry for the ".pdf" extension to associate it with a web browser. This can be done using the regedit command or programmatically through the Windows Registry API.
Locate the registry key: HKEY_CLASSES_ROOT\.pdf
Set the (Default) value to "AcroExch.Document" (for Adobe Acrobat Reader) or "ChromeHTML" (for Google Chrome), depending on the browser you want to associate.
You may also need to modify the registry keys under HKEY_CLASSES_ROOT\[AssociatedKey]\Shell\Open\Command to point to the correct browser executable


Code: Select all  Expand view
#include <Windows.h>
#include <stdio.h>

int main() {
    HKEY hKey;
    LPCSTR fileExtension = ".pdf";
    LPCSTR browserKey = "AcroExch.Document"; // Change this to "ChromeHTML" for Chrome

    // Open the registry key for the file extension
    if (RegOpenKeyEx(HKEY_CLASSES_ROOT, fileExtension, 0, KEY_WRITE, &hKey) != ERROR_SUCCESS) {
        printf("Failed to open registry key\n");
        return 1;
    }

    // Set the default value to the browser key
    if (RegSetValueEx(hKey, NULL, 0, REG_SZ, (BYTE*)browserKey, strlen(browserKey) + 1) != ERROR_SUCCESS) {
        printf("Failed to set registry value\n");
        RegCloseKey(hKey);
        return 1;
    }

    printf("PDF file association with the browser has been set successfully.\n");

    // Close the registry key
    RegCloseKey(hKey);

    return 0;
}
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Associate PDF file with browser

Postby Ari » Mon May 29, 2023 11:19 am

:D

Chat is really good!

thank you very much
Thanks,
Ari

FWH 2212 - Harbour 3.2.0 - Embarcadero 7.43 - MySQL
São Paulo - SP - Brasil
www.sisrev.com.br
User avatar
Ari
 
Posts: 228
Joined: Fri Feb 03, 2006 4:21 pm
Location: São Paulo, SP - Brazil


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 103 guests