Friday, January 25, 2008

calling an external script and passing back a result

Maxthon plugins are known to be able to use features which are normally restricted in regular embeded page script. However, even a plugin has it's limitations. One of those limitations is working with the WMI interface.


There is however a method to get around this limitation. Plugins are allowed to use most all ActiveX objects, and two of the most commonly used are the Windows Script Host and the File System Object. The solution is to place all WMI related script in an external file, separate from the regular plugin code. Then you simply use WSH to run this external script.


But what if you need access to results produced by the called script? Again there's likely more methods, but I found two methods to be most useful. If the result is only a single, numeric value, the easiest woulld be to pass the return value though the WSH exitcode.


In your plugin you then assign the result of the WSH call to a variable which you can test to have your plugin take action accordingly


testResult = oWSH.Run(<plugin.path>ExternalScript  [arguments] , 0 , false)


in the ExternalScript file (js or vbs) you then include as last execution line something like


Wscript.Quit(myReturnCode) (possible values range from 0 to 255)





Another method would be to have your external script place the results in a text file and then have your plugin parse this textfile after the call to the external script (thanks to abc@home for this last tip)

Labels: ,

0 Comments:

Post a Comment

<< Home