Execution of a windows program from classic page

Description

Launching a process from the browser on a local Windows workstation might be a need in some cases, but doing this might create a security flaw. A dedicated feature allows to call windows executable as long as they have been registred in the registry.

This new functionality allows to launch an application (i.e. process) on the local workstation, from a classic page session, using 4GL Callui statement, relayed by Asynchronous Pluggable Protocols stack (APP in the following). Unlike System 4GL statement, this implementation does not support I/O flow control on called process. It's just a "Launch & forget" mode, in an asynchronous way.

To use this new functionality, Windows registry on local workstation must be updated in order to register the application to launch, based on APP specification (see https://msdn.microsoft.com/en-us/library/aa767914(v=vs.85).aspx).

Every application that can be launched is identified by a unique name (the APP protocol name). For example, let's imagine we want to launch "notepad.exe". In this example, we called this component "SageX3ProtocolTest". The APP protocol must be registered for "SageX3ProtocolTest" by adding this Windows registry branch :
[HKEY_CLASSES_ROOT\SageX3ProtocolTest]@="URL:SageX3ProtocolTest""URL Protocol"=""[HKEY_CLASSES_ROOT\SageX3ProtocolTest\shell][HKEY_CLASSES_ROOT\SageX3ProtocolTest\shell\open][HKEY_CLASSES_ROOT\SageX3ProtocolTest\shell\open\command]@="notepad.exe"
The corresponding 4GL script is :
Local Char RETOUR(250)Callui RETOUR="" With "UIAction="+chr$(1)+"OpenFile",& "UILocalDir="+ chr$(1) +"APP",& "UIWindowTimeOut="+ chr$(1) +"10000",& "UIWindowFeatures="+ chr$(1) +"width=300,height=300",& "UILocalFile="+ chr$(1) +"SageX3ProtocolTest:

Warning

If the process to call requires command line arguments, you have to be aware that, at the end, the command line propagated to the called process will contain the APP protocol name (SageX3ProtocolTest: in our sample). So, the called process must be able to parse properly this command line, in order to skip/ignore the protocol name.
Otherwise, if the called process can't deal with this constraint, it's possible to workaround this by calling the process via a DOS script, like described below. In this case, both 4GL script and Windows registry data must be adapted accordingly.
Below the Windows registry data, the 4GL script and the DOS script, based on the same sample (i.e. launch notepad.exe and edit a text file) :

Registry

[HKEY_CLASSES_ROOT\SageX3ProtocolTest]@="URL:SageX3ProtocolTest""URL Protocol"=""[HKEY_CLASSES_ROOT\SageX3ProtocolTest\shell][HKEY_CLASSES_ROOT\SageX3ProtocolTest\shell\open][HKEY_CLASSES_ROOT\SageX3ProtocolTest\shell\open\command]@="c:\\temp\\test_app_notepad.bat \"%1\""

The corresponding 4GL script is

Local Char RETOUR(250)Callui RETOUR="" With "UIAction="+chr$(1)+"OpenFile",& "UILocalDir="+ chr$(1) +"APP",& "UIWindowTimeOut="+ chr$(1) +"10000",& "UIWindowFeatures="+ chr$(1) +"width=300,height=300",& "UILocalFile="+ chr$(1) +"SageX3ProtocolTest:~C:\Tem",& "UILocalFile="+ chr$(2) +"p\test_app.txt"

The DOS script

The script is called test_app_notepad.bat, according to our example.

Command line relayed by APP is split (see ~ character) in order to retrieve the right part, meaning the end application startup arguments.

@echo offfor /f "delims=~ tokens=1,2" %%a in (%1) do set param=%%bstart notepad %param%