Tuesday, November 10, 2009

How to Launch an external executable from Siebel

There are many ways of doing this. Here are two -

1. The first approach is a bit easier than the second. The script is written in the Applet_Load event of the Applet Browser Script. You can also invoke the executable file from a button click etc...

Script

function Applet_Load ()
{
//Instantiate an ActiveX shell Objext.
var wshell = new ActiveXObject("WScript.Shell");
var oFSO = new ActiveXObject("Scripting.FileSystemObject");

//the path of where this file has been installed
sDirectory = "C:\\PROGRA~1\\WINDOW~1\\ACCESS~1\\";

sFile = "wordpad.exe";
sFilePath = sDirectory + sFile;

//Check if the .exe file is installed
if(oFSO.FileExists(sFilePath))
{
execRet = wshell.Run(sFilePath, 3, false);
}
else
{
alert("You do not Wordpad Installed.");
}

oFSO = null;
wshell = null;
return ("CancelOperation");
}


Now, When the applet loads wordpad will open.

2. The second approach uses a setTimeout JavaScript function that offers executing a function after a sleep duration. Then a new function must be created (waitForExecCompleted in the below example); this function will perform the test on the status of the external application: If the application is still running, re-execute itself after a while If the application is completed, run the rest of code


Script

//Global Declaration

var execRet;

function waitForExecCompleted()
{
if(execRet.Status == 0)
setTimeout("waitForExecCompleted()", 100);
else
{
execRet = null;
alert("Completed");
}
}

function launchExternalApplication()
{
var wShell = new ActiveXObject("WScript.Shell");

//File path
execRet = wShell.Exec("C:\\WINNT\\system32\\calc.exe");
waitForExecCompleted();
}



Cheers!

No comments:

Post a Comment

Share/Bookmark