var Shell = {
  '$err'  : function(m) {
   var msg = m || 'Security exception';
   window.alert('[Shell] script object\n\n' + msg);
  }
, 'MSIE'  : (  (typeof window != 'undefined')
            && (typeof window.ActiveXObject != 'undefined'))
, 'Gecko' : (  (typeof window != 'undefined')
            && (typeof window.netscape != 'undefined')
            && (typeof window.netscape.security != 'undefined')
            /* that Opera... always pretending to do everything
             * everywhere but not really doing anything of it...
             */
            && (typeof window.opera != 'object'))
, 'run'   : function(path, args) {
   if ((typeof path == 'string') && (path != '')) {
    if ((Shell.MSIE) && (typeof Shell.$ == 'undefined')) {
     /* If first time, try to instantiate ActiveX object
      * for shell access:
      */
     try {
      Shell.$ = new ActiveXObject('WScript.Shell');
     }
     catch(e) {
      Shell.$err(e.message);
      return null;
     }
    }
    /*
     */
    if (Shell.MSIE) {
     var arg = ((typeof args == 'string') && (args != '')) ?
     (' "' + args + '"') : '';
     var exe = '"'.concat(path, '"', arg);
     try {
      Shell.$.Run(exe);
     }
     catch(e) {
      Shell.$err(e.message);
     }
    }
    else if (Shell.Gecko) {
     /* Netscape security model grants privileges
      * on the per-call per-context basis; thus
      * privilege request and privilege usage
      * have to be in the same block.
      */
     try {
      netscape.security.PrivilegeManager.
      enablePrivilege('UniversalXPConnect');
      Shell.$ = Components.classes['@mozilla.org/file/local;1'].
      createInstance(Components.interfaces.nsILocalFile);
      Shell.$.initWithPath(path);
      if ((typeof args == 'string') && (args != '')) {
       Shell._ = Components.classes['@mozilla.org/process/util;1'].
       createInstance(Components.interfaces.nsIProcess);
       Shell._.init(Shell.$);
       Shell._.run(false, [args], 1);
      }
      else {
       Shell.$.launch();
      }
     }
     catch(e) {
      Shell.$err(e.message);
     }
    }
    else {
     Shell.$err('not supported on this platform');
    }
   }
   else {
    Shell.$err('Invalid argument');
   }
  }
 };
