Altova XMLSpy 2023 Enterprise Edition

The JScript below starts the application and shuts it down. If the COM object of the 32-bit XMLSpy cannot be found, the code attempts to get the COM object of the 64-bit application; otherwise, an error is thrown. If an instance of the application is already running, the running instance will be returned.



Note:For 32-bit XMLSpy, the registered name, or programmatic identifier (ProgId) of the COM object is XMLSpy.Application. For 64-bit XMLSpy, the name is XMLSpy_x64.Application. Be aware, though, that the calling program will access the CLASSES registry entries in its own registry hive, or group (32-bit or 64-bit). Therefore, if you run scripts using the standard command prompt and Windows Explorer on 64-bit Windows, the 64-bit registry entries will be accessed, which point to the 64-bit XMLSpy. For this reason, if both XMLSpy 32-bit and 64-bit are installed, special handling is required in order to call the 32-bit XMLSpy. For example, assuming that Windows Scripting Host is the calling program, do the following:


1.Change the current directory to C:\Windows\SysWOW64.

2.At the command line, type wscript.exe followed by the path to the script that you would like to run, for example:


wscript.exe "C:\Users\...\Documents\Altova\StyleVision2023\StyleVisionExamples\API\JScript\start.js"wscript.exe "C:\Users\...\Documents\Altova\XMLSpy2023\Examples\API\JScript\start.js"



// Initialize application's COM object. This will start a new instance of the application and
// return its main COM object. Depending on COM settings, the main COM object of an already
// running application might be returned.
try {   objSpy = WScript.GetObject("", "XMLSpy.Application");   }
catch(err) {}
if( typeof( objSpy ) == "undefined" )
  try   {   objSpy = WScript.GetObject("", "XMLSpy_x64.Application")   }
     WScript.Echo( "Can't access or create XMLSpy.Application" );
// if newly started, the application will start without its UI visible. Set it to visible.
objSpy.Visible = true;
WScript.Echo(objSpy.Edition + " has successfully started. ");
objSpy.Visible = false;      // will shutdown application if it has no more COM connections
//objSpy.Visible = true;   // will keep application running with UI visible



The JScript code listed above is available in the sample file Start.js (see Example Files).

© 2017-2023 Altova GmbH