Reindexing WHS 2011’s DNLA Server

Searching for this subject reveals a couple of links of which each has some issues. So I started combining code and testing in so I would be able to rebuild the index without restarting the server.

The reason for rebuilding is that the indexing seems to work on directory notifications and also indexes files that are moved out of the indexed folders. If that happens one will start seeing drive letters in the DNLA file lists.

This proved somewhat more difficult. The database called ‘CurrentDatabase_372.wmdb’ is located under the profile of a special user called ‘MediaStreamingAdmin’. The processes related to the DNLA server also run under this account. Basically these are the services whsmss (Windows Server Media Streaming and HomeGroup Service) and WMPNetworkSvc (Windows Media Player Network Sharing Service).

Both services needs to be stopped before an attempt to delete the database can be made.

This however still fails when the server has run for a while and midnight has passed. The reason is that two other processes are started under the same account and accessing the same database (most solutions ignore this and ask to reboot the server before triggering a reindex).

These two processes are WMPAxHost .exe and WMPlayer.exe. WMPAxHost seem to control the WMPlayer.exe process and restart it when terminated. The purpose of these two processes seems to be updating the metadata of the media files with internet based metadata. This is probably the same feature WMPlayer offers when started interactively.

Terminating these processes will not be a problem as they are restarted next midnight. It’s off-course obvious that WMPAxHost has to be terminated before WMPlayer. To kill these processes some force has to be applied (hence the /f switches of the taskkill statements).

During the search for a solution I also came a way to disable and enable the Media Sharing with PowerShell commands. I have not tested if the batch file runs without these two lines as I find it more elegant to disable the Media Sharing feature during modification.

The last trick used is to rename the database file (which is under Windows NT or later allowed on files that are open). So even if final delete of the renamed database in the script fails, next reboot would create a new database.

The complete script looks like:

cd /d c:\program files\windows server\bin

wsspowershell.exe set-wssmediaserverenabled “-enable 0”

net stop whsmss
net stop WMPNetworkSvc

taskkill /f /im wmpaxhost.exe
taskkill /f /im wmplayer.exe

ren “C:\Users\MediaStreamingAdmin\AppData\Local\Microsoft\Media Player\CurrentDatabase_372.wmdb” *.old

net start WMPNetworkSvc
net start whsmss

wsspowershell.exe set-wssmediaserverenabled “-enable 1”

del “C:\Users\MediaStreamingAdmin\AppData\Local\Microsoft\Media Player\CurrentDatabase_372.old”

Advertisements
This entry was posted in Windows. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s