Introduction to scripting: Difference between revisions

From MediaMonkey Wiki
Jump to navigation Jump to search
No edit summary
 
(27 intermediate revisions by 12 users not shown)
Line 1: Line 1:
== How to create a custom MediaMonkey script ==
MediaMonkey can be customized through the use of custom scripts. Scripts are relatively simple computer programs written in a scripting language, such as VBScript. Unlike most computer programs, these scripts do not have to be compiled, which allows them to be tested and modified more easily than with more advanced languages. Still, writing MediaMonkey scripts can be a challenging experience so potential script writers should consider alternatives, particularly if they have little previous experience writing scripts.


# Create a file in Scripts folder, e.g. ‘MyScripts.vbs’.
== Considerations ==
# Write a VB script there and put a callable code to some procedure, e.g.
#: Sub CallMe
#:  ‘ … write some code here
#: End Sub</source>
# Define the new script in Scripts.ini file (see below how to do it).


You can get more information about scripting in general at [http://www.microsoft.com/scripting] (for example VBScript and JScript documentation is there).
Before writing their own scripts, users of MediaMonkey may wish to consider the following issues:
*In addition to supporting scripting, MediaMonkey has a [[Plug-ins|plug-in]] interface that allows a large number of Winamp and MediaMonkey plug-ins to be used. There may be no need to write a script if the desired features are already provided by a plug-in.
*Some users of MediaMonkey are willing to share the scripts that they have written with other users. An existing script may already provide the desired features or be relatively easily modified so that it does. The best place to find such scripts or to get support for them is the [http://www.mediamonkey.com/forum/viewforum.php?f=2 Scripts and Components forum].
*Although, in theory, MediaMonkey supports both of the [http://en.wikipedia.org/wiki/VBScript VBScript] (*.vbs) and [http://en.wikipedia.org/wiki/JScript JScript] (*.js) scripting languages, the implementation for JScript is only partial (see [[Scripting Tips & Tricks#JScript|Scripting Tips & Tricks]] for some issues), so for some applications VBScript is required. Programmers not wishing to deal with VBScript may wish to create an [[#About external scripts and applications |external]] script or application using their preferred language and use a script written in VBScript (or JScript) to launch it.
*Other than tags embedded in media files, virtually all of MediaMonkey’s data is stored in a [http://www.sqlite.org SQLite] database from MediaMonkey version 3.0. It is possible to manipulate MediaMonkey’s data, while minimizing the use of MediaMonkey’s API, by using [http://en.wikipedia.org/wiki/SQL SQL]. MediaMonkey's API can be (almost, except string [[MediaMonkey_Database_structure#Additions_to_SQLite|collations]]) completely bypassed by using an interface provided by the underlying engine to access the database. (MediaMonkey 2.x used [http://en.wikipedia.org/wiki/Microsoft_Jet_Database_Engine Microsoft Jet] relational database. It could accessed through Jet or ODBC, or even opened directly by Microsoft Access, for example.)


In order to work with MediaMonkey’s objects from your scripts, there is 'SDB' object always present so that you can access its properties and methods. In case you work outside of MediaMonkey’s scripts (e.g. you create an ASP page) you can create this object by the following code:
== Types of scripts ==
 
There are three major types of scripts that can be launched internally by MediaMonkey:
*'''Normal scripts''' are located in the ''Scripts'' folder and are executed according to the script's entry in the [[#Format of the Scripts.ini file|''Scripts\Scripts.ini'' file]].
*'''Auto-scripts''' are located in the ''Scripts\Auto'' folder and its OnStartup method is executed when MediaMonkey starts. If more than one script exists in the Auto folder the scripts are run in alphabetical order.
*'''Other scripts''', such as [[Search scripts]] and [[Auto-DJ scripts]] are intended for specific types of customization, but are also defined in the [[#Format of the Scripts.ini file|''Scripts\Scripts.ini'' file]].
 
In addition to the scripts that are launched by MediaMonkey (internal scripts), you can also work with MediaMonkey by using [[#About external scripts and applications|''external'' scripts and applications]].
 
== How to create a normal script ==
 
<ol>
<li>Create a plain text file in the ''Scripts'' folder, e.g. ''MyNormalScript.vbs''.</li>
<li>Write your VBScript script and make sure you have a procedure that can be called, e.g.
<source lang="vb">Sub CallMe
 
    ' This script will pop up a simple message box when the procedure CallMe is called.
    MsgBox "CallMe was called by the action defined in the Scripts.ini file."
 
End Sub</source></li>
<li>Create a new entry for your script's ''CallMe'' procedure in the [[#Format of the Scripts.ini file|''Scripts.ini'' file]].</li>
</ol>
 
From within a MediaMonkey script, a reference to the SDB object (an instance of the [[SDBApplication]] class) is always present. By accessing its properties and methods, you can interact with many aspects of MediaMonkey. Check out the [[MediaMonkey Automation objects]] page for other MediaMonkey objects that can be created starting from the SDB object.
Another available object reference is the Script object (an instance of the [[SDBScriptControl]] class), that contains methods to control the running script's environment, usually to [[ISDBScriptControl::RegisterEvent|attach]] to events of MediaMonkey and its player and controls (see examples [[Sample Event Handlers script|1]] and [[Sample Events for User Interface script|2]]).
 
The script ''Scripts\MediaMonkey init.vbs'' is always executed just before any other script. It contains some constants that can be used in your own script.
 
 
A good and quite complex example is ''Scripts\Export.vbs'' (distributed with MediaMonkey) which contains code that takes care of all export features of MediaMonkey. For more examples, check out the [[Sample scripts|sample scripts page]] or, if you are already up to it, take a look at the code of some actively developed [http://www.mediamonkey.com/forum/viewforum.php?f=2 scripts on the forum] (most of them are distributed in [[Installation_Packages#Installation_Packages_structure|MM installation packages]]).
 
More information about scripting in general can be found at [http://msdn2.microsoft.com/en-us/library/ms950396.aspx Microsoft Scripting] (with official VBScript and JScript documentation).
 
== How to create an auto-script ==
 
<ol>
<li>Create a plain text file in the ''Scripts\Auto'' folder, e.g. ''MyAutoScript.vbs''.</li>
<li>Write your VBScript script and use the procedure ''OnStartup'' as start point for execution, e.g.
<source lang="vb">
<source lang="vb">
Dim SDB
Sub OnStartup
Set SDB = CreateObject( "SongsDB.SDBApplication")
 
</source>
    ' This script will pop up a simple "Hello World!" message box when you start MediaMonkey.
    MsgBox "Hello World!"
 
End Sub
</source></li>
</ol>


'MediaMonkey init.vbs' file is always executed before your script and therefore it contains some constants that can be later used in your script.
All VBScript, but not JScript, scripts in the ''Scripts\Auto'' folder are automatically checked during MM start-up, and the '''OnStartup''' procedure (if present) is called. Auto-scripts make it possible to add user interface enhancements such as new menu or toolbar items, new option sheets, etc.


More information about properties and methods of SDB object about other objects and some samples can be found in [MediaMonkey Automation objects]. A good and quite complex example of a script is Export.vbs (distributed with MediaMonkey) which contains code that takes care of all export features of MediaMonkey.
Except that these scripts are automatically executed when MediaMonkey starts, they behave identical as the normal scripts. They also get a reference to the SDB object, and the constants defined in ''Scripts\MediaMonkey init.vbs'' are always usable.


== Automatically called scripts ==
You can choose to dynamically add an entry to the Scripts.ini from your code, so your script can be accessed from the Tools > Scripts submenu just like normal scripts. However, most auto-scripts add UI items (e.g. menu items) directly to the MediaMonkey user interface to be more tightly integrated.


All .vbs scripts in Scripts\Auto folder are automatically checked during MM start-up and in case there is ‘OnStartup’ procedure present, it is called. This allows to add for example user interface enhancements like new menu or toolbar items, new option sheets, etc. For more information about how to do it see sample scripts and MM scripting reference.


== Format of Scripts\Scripts.ini file ==
== Format of the ''Scripts.ini'' file ==


This file is a standard .ini file where each section defines one custom script. Section starts with a section identifier [SectionName], where ‘SectionName’ is a unique name of the script. Then follow several lines the further describe the script:
<div style="float: right; margin-left: 1em; margin-bottom: 0.5em; clear: right; background-color:#F9F9F9; border:1px solid #CCCCCC; font-size:95%; padding:5px;">
<source lang="ini">
[AutoIncTrackN]
FileName=AutoIncTrackN.vbs
ProcName=AutoIncTrackNumbers
Order=1
DisplayName=Auto-&increment Track #s...
Description=Sequentially numbers Tracks
Language=VBScript
ScriptType=0
</source>
<div style="position: relative; top: -6px; left: 5px">Sample ''Scripts.ini'' entry</div>
</div>
 
This ''Scripts\Scripts.ini'' file is a standard .ini file where each section defines a procedure in a script. The section starts with a section identifier [SectionName], where ‘SectionName’ is a unique name of the script entry.
These are the entry's properties:
; Filename
; Filename
: Name of a file where the script is located, e.g. ‘MyScripts.vbs’.
: Path of a script file where the procedure is located, relative to the ''Scripts'' folder, e.g. ‘MyScripts.vbs’.
; ProcName
; ProcName
: Name of a procedure to be called when the script is executed in MM. This procedure must exist in the ‘Filename’ specified above.
: Name of an existing procedure to be called when the script (specifiedby ‘Filename’) is executed in MM.
; ScriptType
; ScriptType
: Defines type of the script:
: Defines type of the script:
:* 0 = A standard script that appears in Tools\Scripts submenu.
:* 0 = A ''standard script'' that appears in the <code>Tools > Scripts</code> submenu.
:* 1 = An export script that can be found in File\Export submenu.
:* 1 = An ''export script'' that can be found in the <code>File > Create Reports</code> submenu.
:* 2 = A procedure that is called whenever a new track is started. This script doesn’t appear in any menu, it’s simply called in the background. When this procedure is executed, there is 'CurrentTrack' variable of [[SDBSongData]] object defined and you can use it to get information about the track.
:* 2 = A ''track-start script'' that is activated whenever a new track is started. This script doesn’t appear in any menu, it’s simply called in the background. When this procedure is executed, a variable 'CurrentTrack' (object of the [[SDBSongData]] class) is defined, and you can use it to get information about the started track. This script type is obsolete, rather register OnPlay event. Also note, that this is the only case, when multiple instances of one script can be executed by MediaMonkey, otherwise only one instance is always executed.
:*      3 = A ''search script'' that allows custom searches to be programmed in the "Auto-tag from Web" dialog. See [[Search scripts]] for more information about this more complex script type.
:*      4 = An ''Auto-DJ script'' that can handle content added by Auto-DJ. See [[Auto-DJ scripts]] for more details.
; Order
; Order
: Defines the order of the script in its section. These numbers are sorted and scripts are listed according to the order then.
: Defines the order of the script in its section. These numbers are sorted and scripts are listed according to the order.
; DisplayName
; DisplayName
: The script is listed under this name in MediaMonkey menu.
: The script is listed as menu item with this name.
; Description
; Description
: This is shown as a tooltip when mouse is over the script in menu.
: Message shown as tooltip when the mouse is moved over the menu item.
; Language
; Language
: Is usually VBScript, but can be any other scripting language, e.g. JScript.
: The script language of the referenced script. Usually <tt>VBScript</tt>, but can be <tt>JScript</tt> too (although this is not recommended).
; Shortcut
; Shortcut
: Can specify a shortcut that will invoke the script in MM. You can use any of the string ‘Shift+’, ‘Ctrl+’ or ‘Alt+’ even combined together and followed either by a single letter or by a special key, which are: BkSp, Tab, Enter, Esc, Space, PgUp, PgDn, End, Home, Left, Up, Right, Down, Ins, Del.
: Specifies a shortcut that invokes the script in MM. You can use any of the strings ‘Shift+’, ‘Ctrl+’ or ‘Alt+’, singly or combined, followed a single letter or number, or the name of a special key - BkSp, Tab, Enter, Esc, Space, PgUp, PgDn, End, Home, Left, Up, Right, Down, Ins, Del.
 
== About external scripts and applications ==
 
(see also [[Scripting_Tips_&_Tricks#Interaction_with_MediaMonkey_from_outside|Interaction with MediaMonkey from outside]])
 
Besides supporting al large part of the Winamp [http://wiki.winamp.com/wiki/Plug-in_Developer plug-in model] and messages ([http://wiki.winamp.com/wiki/SendMessage_API 1],[http://forums.winamp.com/showthread.php?threadid=180297 2]), MediaMonkey exposes an API via the Microsoft COM model. This allows external applications to access and control MediaMonkey directly. These applications can be written in any language that can access COM objects. VBScript can be used to produce external scripts, but regular Visual Basic (or any COM-aware language) can be used as well, producing a full-fledged application.
 
In order to work with MediaMonkey’s objects from an external script or application, you need to create a reference to the SDB object (an instance of the [[SDBApplication]] class) yourself. For .NET-based applications, you must also add a reference to MediaMonkey's COM object "MediaMonkey Library" to your Visual Studio project, so that the compiler can find MediaMonkey and the SongsDB namespace.
 
If MediaMonkey is already running, creating a SDBApplication object instance will return a reference to the running instance. If MediaMonkey is not running yet, it will be started and a reference will be returned. In addition, if MediaMonkey was was not running before, it will normally shut down automatically when the external script/application exits. This can be prevented (so MediaMonkey will remain running) by setting SDB's [[ISDBApplication::ShutdownAfterDisconnect|ShutdownAfterDisconnect]] property to False.
 
 
'''Visual Basic / VBScript sample:'''
<source lang="vb">
Dim SDB : Set SDB = CreateObject("SongsDB.SDBApplication")
 
SDB.ShutdownAfterDisconnect = False    ' in case you want to keep an opened instance open after disconnecting the SDB object
</source>
'''C# sample:'''
<source lang="csharp">
SongsDB.SDBApplication SDB = new SongsDB.SDBApplication();
 
SDB.ShutdownAfterDisconnect = false;    // in case you want to keep an opened instance open after disconnecting the SDB object
</source>
 
'''C++/CLI sample:'''
<source lang="cpp">
SongsDB::SDBApplication^ SDB = gcnew SongsDB::SDBApplication();
 
SDB->ShutdownAfterDisconnect = false;    // in case you want to keep an opened instance open after disconnecting the SDB object
</source>
 
'''Delphi sample:'''
<source lang="delphi">
var
  SDB : Variant;
begin
  SDB := CreateObject('SongsDB.SDBApplication');
  SDB.ShutdownAfterDisconnect := false;    // in case you want to keep an opened instance open after disconnecting the SDB object
</source>
 
'''PHP sample:''' (shows initialization only)
<source lang="php">
$objSDB = new COM('SongsDB.SDBApplication') or die('Cannot create MediaMonkey SDB Object');
</source>
 
'''Python (with PyWin32) sample:'''
<source lang="python">
try:
      import win32com.client
except:
      print "Install PyWin32"
# Open connection to COM object
try:
      SDB = win32com.client.Dispatch("SongsDB.SDBApplication")
except:
      print "Is MediaMonkey up and running?"
 
SDB.ShutdownAfterDisconnect = False
</source>
 
'''Perl sample:''' (shows initialization only)
<source lang="perl">
use Win32::OLE;
my $SDB = Win32::OLE->GetActiveObject('SongsDB.SDBApplication') || Win32::OLE->new('SongsDB.SDBApplication', '');
$SDB->ShutdownAfterDisconnect(true);
</source>
 
 
Developers that require MediaMonkey type library information (e.g. for C++/Delphi, as newer languages usually don't need this) can extract this from the MediaMonkey.exe file ([http://msdn.microsoft.com/en-us/library/ms680581(v=vs.85).aspx more information]), or can use #import on the Exe file as explained in [http://msdn.microsoft.com/en-us/library/8etzzkb6(v=vs.71).aspx this MSDN page].
 
 
== Further reading ==
* [[Scripting|Scripting main page]]
* [[.NET|.NET Tips page]]
* [http://www.mediamonkey.com/sw/MediaMonkey.idl MediaMonkey Interface Definition Language (IDL) file]

Latest revision as of 23:16, 25 November 2014

MediaMonkey can be customized through the use of custom scripts. Scripts are relatively simple computer programs written in a scripting language, such as VBScript. Unlike most computer programs, these scripts do not have to be compiled, which allows them to be tested and modified more easily than with more advanced languages. Still, writing MediaMonkey scripts can be a challenging experience so potential script writers should consider alternatives, particularly if they have little previous experience writing scripts.

Considerations

Before writing their own scripts, users of MediaMonkey may wish to consider the following issues:

  • In addition to supporting scripting, MediaMonkey has a plug-in interface that allows a large number of Winamp and MediaMonkey plug-ins to be used. There may be no need to write a script if the desired features are already provided by a plug-in.
  • Some users of MediaMonkey are willing to share the scripts that they have written with other users. An existing script may already provide the desired features or be relatively easily modified so that it does. The best place to find such scripts or to get support for them is the Scripts and Components forum.
  • Although, in theory, MediaMonkey supports both of the VBScript (*.vbs) and JScript (*.js) scripting languages, the implementation for JScript is only partial (see Scripting Tips & Tricks for some issues), so for some applications VBScript is required. Programmers not wishing to deal with VBScript may wish to create an external script or application using their preferred language and use a script written in VBScript (or JScript) to launch it.
  • Other than tags embedded in media files, virtually all of MediaMonkey’s data is stored in a SQLite database from MediaMonkey version 3.0. It is possible to manipulate MediaMonkey’s data, while minimizing the use of MediaMonkey’s API, by using SQL. MediaMonkey's API can be (almost, except string collations) completely bypassed by using an interface provided by the underlying engine to access the database. (MediaMonkey 2.x used Microsoft Jet relational database. It could accessed through Jet or ODBC, or even opened directly by Microsoft Access, for example.)

Types of scripts

There are three major types of scripts that can be launched internally by MediaMonkey:

  • Normal scripts are located in the Scripts folder and are executed according to the script's entry in the Scripts\Scripts.ini file.
  • Auto-scripts are located in the Scripts\Auto folder and its OnStartup method is executed when MediaMonkey starts. If more than one script exists in the Auto folder the scripts are run in alphabetical order.
  • Other scripts, such as Search scripts and Auto-DJ scripts are intended for specific types of customization, but are also defined in the Scripts\Scripts.ini file.

In addition to the scripts that are launched by MediaMonkey (internal scripts), you can also work with MediaMonkey by using external scripts and applications.

How to create a normal script

  1. Create a plain text file in the Scripts folder, e.g. MyNormalScript.vbs.
  2. Write your VBScript script and make sure you have a procedure that can be called, e.g.
    Sub CallMe
    
        ' This script will pop up a simple message box when the procedure CallMe is called.
        MsgBox "CallMe was called by the action defined in the Scripts.ini file."
    
    End Sub
  3. Create a new entry for your script's CallMe procedure in the Scripts.ini file.

From within a MediaMonkey script, a reference to the SDB object (an instance of the SDBApplication class) is always present. By accessing its properties and methods, you can interact with many aspects of MediaMonkey. Check out the MediaMonkey Automation objects page for other MediaMonkey objects that can be created starting from the SDB object. Another available object reference is the Script object (an instance of the SDBScriptControl class), that contains methods to control the running script's environment, usually to attach to events of MediaMonkey and its player and controls (see examples 1 and 2).

The script Scripts\MediaMonkey init.vbs is always executed just before any other script. It contains some constants that can be used in your own script.


A good and quite complex example is Scripts\Export.vbs (distributed with MediaMonkey) which contains code that takes care of all export features of MediaMonkey. For more examples, check out the sample scripts page or, if you are already up to it, take a look at the code of some actively developed scripts on the forum (most of them are distributed in MM installation packages).

More information about scripting in general can be found at Microsoft Scripting (with official VBScript and JScript documentation).

How to create an auto-script

  1. Create a plain text file in the Scripts\Auto folder, e.g. MyAutoScript.vbs.
  2. Write your VBScript script and use the procedure OnStartup as start point for execution, e.g.
    Sub OnStartup
    
        ' This script will pop up a simple "Hello World!" message box when you start MediaMonkey.
        MsgBox "Hello World!"
    
    End Sub

All VBScript, but not JScript, scripts in the Scripts\Auto folder are automatically checked during MM start-up, and the OnStartup procedure (if present) is called. Auto-scripts make it possible to add user interface enhancements such as new menu or toolbar items, new option sheets, etc.

Except that these scripts are automatically executed when MediaMonkey starts, they behave identical as the normal scripts. They also get a reference to the SDB object, and the constants defined in Scripts\MediaMonkey init.vbs are always usable.

You can choose to dynamically add an entry to the Scripts.ini from your code, so your script can be accessed from the Tools > Scripts submenu just like normal scripts. However, most auto-scripts add UI items (e.g. menu items) directly to the MediaMonkey user interface to be more tightly integrated.


Format of the Scripts.ini file

[AutoIncTrackN]
FileName=AutoIncTrackN.vbs
ProcName=AutoIncTrackNumbers
Order=1
DisplayName=Auto-&increment Track #s...
Description=Sequentially numbers Tracks
Language=VBScript
ScriptType=0
Sample Scripts.ini entry

This Scripts\Scripts.ini file is a standard .ini file where each section defines a procedure in a script. The section starts with a section identifier [SectionName], where ‘SectionName’ is a unique name of the script entry. These are the entry's properties:

Filename
Path of a script file where the procedure is located, relative to the Scripts folder, e.g. ‘MyScripts.vbs’.
ProcName
Name of an existing procedure to be called when the script (specifiedby ‘Filename’) is executed in MM.
ScriptType
Defines type of the script:
  • 0 = A standard script that appears in the Tools > Scripts submenu.
  • 1 = An export script that can be found in the File > Create Reports submenu.
  • 2 = A track-start script that is activated whenever a new track is started. This script doesn’t appear in any menu, it’s simply called in the background. When this procedure is executed, a variable 'CurrentTrack' (object of the SDBSongData class) is defined, and you can use it to get information about the started track. This script type is obsolete, rather register OnPlay event. Also note, that this is the only case, when multiple instances of one script can be executed by MediaMonkey, otherwise only one instance is always executed.
  • 3 = A search script that allows custom searches to be programmed in the "Auto-tag from Web" dialog. See Search scripts for more information about this more complex script type.
  • 4 = An Auto-DJ script that can handle content added by Auto-DJ. See Auto-DJ scripts for more details.
Order
Defines the order of the script in its section. These numbers are sorted and scripts are listed according to the order.
DisplayName
The script is listed as menu item with this name.
Description
Message shown as tooltip when the mouse is moved over the menu item.
Language
The script language of the referenced script. Usually VBScript, but can be JScript too (although this is not recommended).
Shortcut
Specifies a shortcut that invokes the script in MM. You can use any of the strings ‘Shift+’, ‘Ctrl+’ or ‘Alt+’, singly or combined, followed a single letter or number, or the name of a special key - BkSp, Tab, Enter, Esc, Space, PgUp, PgDn, End, Home, Left, Up, Right, Down, Ins, Del.

About external scripts and applications

(see also Interaction with MediaMonkey from outside)

Besides supporting al large part of the Winamp plug-in model and messages (1,2), MediaMonkey exposes an API via the Microsoft COM model. This allows external applications to access and control MediaMonkey directly. These applications can be written in any language that can access COM objects. VBScript can be used to produce external scripts, but regular Visual Basic (or any COM-aware language) can be used as well, producing a full-fledged application.

In order to work with MediaMonkey’s objects from an external script or application, you need to create a reference to the SDB object (an instance of the SDBApplication class) yourself. For .NET-based applications, you must also add a reference to MediaMonkey's COM object "MediaMonkey Library" to your Visual Studio project, so that the compiler can find MediaMonkey and the SongsDB namespace.

If MediaMonkey is already running, creating a SDBApplication object instance will return a reference to the running instance. If MediaMonkey is not running yet, it will be started and a reference will be returned. In addition, if MediaMonkey was was not running before, it will normally shut down automatically when the external script/application exits. This can be prevented (so MediaMonkey will remain running) by setting SDB's ShutdownAfterDisconnect property to False.


Visual Basic / VBScript sample:

Dim SDB : Set SDB = CreateObject("SongsDB.SDBApplication")

SDB.ShutdownAfterDisconnect = False    ' in case you want to keep an opened instance open after disconnecting the SDB object

C# sample:

SongsDB.SDBApplication SDB = new SongsDB.SDBApplication();

SDB.ShutdownAfterDisconnect = false;    // in case you want to keep an opened instance open after disconnecting the SDB object

C++/CLI sample:

SongsDB::SDBApplication^ SDB = gcnew SongsDB::SDBApplication();

SDB->ShutdownAfterDisconnect = false;    // in case you want to keep an opened instance open after disconnecting the SDB object

Delphi sample:

var 
  SDB : Variant; 
begin 
  SDB := CreateObject('SongsDB.SDBApplication');
  SDB.ShutdownAfterDisconnect := false;    // in case you want to keep an opened instance open after disconnecting the SDB object

PHP sample: (shows initialization only)

$objSDB = new COM('SongsDB.SDBApplication') or die('Cannot create MediaMonkey SDB Object');

Python (with PyWin32) sample:

try:
      import win32com.client
except:
      print "Install PyWin32"
# Open connection to COM object
try:
      SDB = win32com.client.Dispatch("SongsDB.SDBApplication")
except:
      print "Is MediaMonkey up and running?"

SDB.ShutdownAfterDisconnect = False

Perl sample: (shows initialization only)

use Win32::OLE;
my $SDB = Win32::OLE->GetActiveObject('SongsDB.SDBApplication') || Win32::OLE->new('SongsDB.SDBApplication', '');
$SDB->ShutdownAfterDisconnect(true);


Developers that require MediaMonkey type library information (e.g. for C++/Delphi, as newer languages usually don't need this) can extract this from the MediaMonkey.exe file (more information), or can use #import on the Exe file as explained in this MSDN page.


Further reading