How can I launch default browser from COBOL? Thanks

Hi all,

My environment: VS 2015, VC 2.32, Windows 10

I'm creating an html page (for a report) and I'd like to show it by launching the user's default browser from my COBOL program. What's the best way to do this?

Thank you,


  • Verified Answer

    I you can either use: CBL_EXEC_RUN_UNIT/SYSTEM API with "cmd /c index.html" or use the Windows API ShellExecute.

    For example:

          $set sourceformat"variable"
          $set ans85 mf defaultbyte"00" case
           copy "windows.cpy".
           identification division.
           program-id. "OpenHTML".
               call-convention 74 is WinAPI.

           data division.
           working-storage section.

           01 se-hInstance             HINSTANCE.
           01 sw-cwd                   pic x(1024).

           78 SHELL-OPEN-CMD-SIZE      value 5.
           01 ShellOpenCmd             pic x(SHELL-OPEN-CMD-SIZE).
           01 hInstResource            HINSTANCE.
           01 lnk-HtmlDocument         pic x(1024).

           local-storage section.
           01 RetCodeString    INT.

           linkage section.
           01 lnk-hInstResource    HINSTANCE.

           procedure division using by reference lnk-HtmlDocument.
               move z"open" to ShellOpenCmd

          * Assume HTML Document is in the current directory!
               call WinAPI GetCurrentDirectory using
                    by value 1024 size 4,
                    reference sw-cwd
          * ShellExecute is used because ShellExecuteEx is not supported
          * on NT 3.51... perhaps in NT 4.0!
               call WinAPI ShellExecute using
                    by value 0 size 4,
                    by reference SHellOpenCmd,
                    by reference lnk-HtmlDocument
                    by value 0 size 4,
                    by reference sw-cwd,
                    by value SW-SHOWNORMAL
                    returning se-hInstance

               exit program returning se-hInstance.


    and to test is use:

                01 html-file        pic x(1024) value z"index.html".

                call "OpenHTML" using by reference html-file

                exhibit named return-code.


    You need to link with shell32.lib to resolve the ShellExecute API

  • Thank you for your reply and time. I will give this a try.
    (I'm not getting reply notifications for some reason hence just found your answer - apols.)
    Regards, Linden.