Everybody dreads the
"You are about to run the following executable for the first time" message you get when using the SHELL command. The workarounds listed below seem to be the most popular.
Each workaround consists of a function with the following variables:
Parameters:
_commandLine Text 1024
_runModally Boolean
Return Value:
exitValue Integer
Local variables:
wSHShell Automation 'Windows Script Host Object Model'.WshShell
wSHExec Automation 'Windows Script Host Object Model'.WshExec
wSHExecStatus Integer
Method 1, using WSHShell.Exec:
CREATE(wSHShell);
wSHExec := wSHShell.Exec(_commandLine);
IF NOT _runModally THEN
EXIT(0);
WHILE wSHExecStatus = 0 DO BEGIN
SLEEP(500);
wSHExecStatus := wSHExec.Status;
END;
EXIT(wSHExec.ExitCode);
Method 2, using WSHShell.Exec:
CREATE(wSHShell);
wSHExec := wSHShell.Exec(
STRSUBSTNO(
'%1 /C %2',
ENVIRON('COMSPEC'),
_commandLine));
IF NOT _runModally THEN
EXIT(0);
WHILE wSHExecStatus = 0 DO BEGIN
SLEEP(500);
wSHExecStatus := wSHExec.Status;
END;
EXIT(WSHExec.ExitCode);
Method 3, using WSHShell.Run:
CREATE(wSHShell);
dummyInt := 1;
EXIT(wSHShell.run(_commandLine,dummyInt,_runModally));
However, none of them are ideal:
Method 1:
Runs both modally and non-modally.
Does not work with associated program types (i.e. passing c:\mytext.txt as _commandLine will NOT launch NotePad (or whatever application has been associated with the txt extension)).
Supports launching of applications (i.e. passing c:\myprog.exe as _commandLine).
Method 2:
Runs both modally and non-modally.
Works with associated program types.
Does not support launching of applications.
Method 3:
Runs non-modally but runs modally in a very strange fashion: NAV will wait for a result from the function before continuing executing code, but at the same time NAV is NOT locked, meaning you can navigate the application exactly like you're used to. You could say that the modality is limited to the call itself, whereas NAV normally expands the modality to the whole application.
Works with associated program types.
Does not support launching of applications.
It's fair to say that Method 3 is inferior to Method 2 if we disregard the much simpler implementation. That leaves Methods 1 and 2 which are unfortunately diametrically opposite: you need them both in your application if you want to run programs both by association and directly. But the worst part is that you can't always be sure which of the functions you need to invoke which leads me to my question:
Has anybody succeeded in creating a function that works with both associated and direct application launching while at the same type suppressing the annoying
"You are about to.." message?
Comments
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
The trick is this: use a Text Constant for the executable. Then it is seen as a trusted executable, that means no annoying question.
See the online help text (F1) for SHELL.
This starts Excel, assuming file type csv is linked to Excel.
I made a function like this: with these local Text Constants:
ExplorerTC = c:\windows\explorer.exe
NotepadTC = c:\windows\notepad.exe
MyProgTC = C:\myprog.exe
Usage:
If you look at my examples, the functions are all called with the command line to execute and cannot be implemented using text constants.
Senior NAV Developer
Elbek & Vejrup