Gregory Hassett
Guest
|
Posted:
Wed Nov 23, 2005 9:30 pm Post subject:
Accessing Windows Media Database |
|
|
I am writing a service which runs in the LOCALSYSTEM account. The service
knows, at installation time, the user who is installing it (say, for
example, "ghassett"). The service does not ask the user for his Windows
password during installation, and does not know it.
When the service runs, it needs to access ghassett's music library --
stored, incidentally at C:\Documents and Settings\ghassett\Local
Settings\Application Data\Microsoft\Media Player\CurrentDatabase_219.wmdb.
This WMDB file is readable by the LOCALSYSTEM account.
The usual way to do this is to use the Windows Media COM component, like the
C# code that follows. Unfortunately, COM does not want to access ghassett's
library, since the service that instantiates the COM object is "logged in"
under the LOCALSYSTEM account.
I would like to either (a) get COM to read the library I want to read and
give me playlists and track information from ghassett's library, or (b)
parse this library file myself to extract the playlists, tracks, etc. Any
ideas?
Thanks!
Greg Hassett
(Here's an extract/simplification of the C# code that runs inside my service
and attempts to walk the playlists inside ghassett's library -- if I run the
service under ghassett's account, all is fine. If I run it under
LOCALSYSTEM (which I must do in the real world), I have the problems stated
above).
private WindowsMediaPlayerClass WMP = null;
WMP = new WindowsMediaPlayerClass ();
ArrayList retval = new ArrayList ();
for (int i = 0; i < WMP.playlistCollection.getAll().count; i++)
{
try
{
IWMPPlaylist playlist = WMP.playlistCollection.getAll().Item(i);
retval.Add (playlist);
}
catch (Exception ex)
{
log (ex);
}
}
return retval;
|
|