How Can I Change the “Copy Music to This Location Folder” in Windows Media Player?
Hey, Scripting Guy! How can I change the Copy music to this location folder in Windows Media Player?
Hey, BD. You know, a lot of people think that the reason we Scripting Guys don’t do very much work is because we’re just plain lazy. Those people are right. However, what we tell our bosses is this: it’s hard for us to do any work because every time we write a script we get hundreds of questions related to that script. That proved to be the case when we released our article – The Scripting Guys Really Do Rock – that talked about scripting Windows Media Player. No sooner did we release the article than we were inundated with millions of questions about scripting Windows Media Player. Trust us, it’s not easy for a bunch of lazy guys to answer millions of questions.
Editor’s Note: “Millions” might be exaggerating just a little.
But while we look into doing more articles on Windows Media Player we’ll try to address a few of these million or so questions in this column. As you noted in your email, BD, you’re having a problem with users automatically saving music files to your file servers; you’d like to be able to set the default location for saving music files and you’d like to be able to do it using a script.
Before we go any further we should point out that in Windows Media Player 10 this option is no longer called Copy music to this location; instead, it’s called Rip music to this location. You can find the default folder setting in the Options dialog box on the Rip Music tab:
As you can see, on this computer new music files will be saved, by default, to the folder D:\Music.
So can you change the default location using a script? As a matter of fact, you can. The value for the rip music folder is actually stored in the registry; you’ll find it here:
And, yes, for some reason the registry value is named CDRecordPath. But the name doesn’t matter; all that matters is that we can use a script to connect to this registry value and then set the default folder path to any valid folder we have access to. (Note that if you’ve never changed the path, you might not see CDRecordPath in your registry until after you’ve changed the value. But trust us, this will still work.)
In fact, here’s a script that changes the default folder setting to C:\Audio:
Const HKEY_CURRENT_USER = &H80000001
strComputer = “.”
Set objRegistry=GetObject(“winmgmts:\\” & _
strComputer & “\root\default:StdRegProv”)
strKeyPath = “SOFTWARE\Microsoft\MediaPlayer\Preferences”
strValueName = “CDRecordPath”
strValue = “C:\Audio”
We begin by defining a constant named HKEY_CURRENT_USER and setting the value to &H80000001; we’ll use this later on to indicate which portion of the registry we want to work with. We then connect to the WMI service, binding to the standard registry provider class (StdRegProv) in the root\default namespace. We then assign values to three variables:
strKeyPath, which is assigned the registry path within HKEY_CURRENT_USER (Software\Microsoft\MediaPlayer\Preferences).
strValueName, which is assigned the name of the registry value we want to change (CDRecordPath).
strValue, which is assigned the new folder location (C:\Audio).
Next we call the SetStringValue method, passing the HKEY_CURRENT_USER constant and the preceding three parameters. That will change the value in the registry and, in turn, change the default folder location for copying (or, if you prefer, ripping) music.