How to Create Windows Media Encoder Files with WSH (290898)



The information in this article applies to:

  • Microsoft Windows Media Encoder 7
  • Microsoft Windows Media Encoder 7.1

This article was previously published under Q290898

SUMMARY

This article describes how to automatically create a Windows Media Encoder configuration file (.wme) with Windows Scripting Host (WSH).

MORE INFORMATION

DISCLAIMER

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

CODE SAMPLE

To use this sample, copy the WSH code into Notepad, and then save it in a folder containing .wma, .wav, or .mp3 files as "Makewme.vbs". To run the sample, double-click the file that you saved. The example code will automatically create a .wme file that you can open with the Windows Media Encoder.
Option Explicit

' ********** define all variables **********

Dim objFSO
Dim objFolder
Dim objFile
Dim objWME
Dim strExt
Dim strName
Dim strGUID

' ********** Verify WSH Version **********

' minimum Windows Script Host (WSH) level
Const intMinWSH = 5
' check for WSH version and exit if to old
If CLng(WScript.Version) < intMinWSH Then
  MsgBox "You must have at least Windows Script Host version " & _
    intMinWSH & " to use this script.", vbCritical, "WSH Version Error"
  WScript.Quit
End If

' ********** define some general constants **********

' valid file extensions to search for
Const strValid = ".wma.mp3.wav"
' broadcast port
Const intPort = 1755

' ********** set encoder level **********

' Near-CD Quality (64kbps)
Const str64KBPS  = "GUID {B29CFFC6-F131-41DB-B5E8-99D8B0B945F4}"
' CD Quality (96kbps)
Const str96KBPS  = "GUID {A9D4B819-16CC-4A59-9F37-693DBB0302D6}"
' CD Quality Transparency (128kbps)
Const str128KBPS = "GUID {C64CF5DA-DF45-40D3-8027-DE698D68DC66}"
' set the encoder to 128kbps (change to desired level)
strGUID = str128KBPS

' ********** create the WME file **********

' get a File System Object to use
Set objFSO = CreateObject("Scripting.FileSystemObject")
' get an object for the current folder
Set objFolder = objFSO.GetFolder(".")
' create a WME file named after the folder
Set objWME = objFSO.CreateTextFile(objFolder.Name & ".wme",True,True)

' start the WME code, using the folder name as the title
objWME.WriteLine "<?xml version=""1.0""?>"
objWME.WriteLine vbTab & "<WMEncoder major_version=""7"" minor_version=""0"" Name=""WMEncoder29787"">"
objWME.WriteLine vbTab & "<Description Title=""" & objFolder.Name & """/>"
objWME.WriteLine vbTab & "<SourceGroups>"

' loop through the files collection
For Each objFile In objFolder.Files
  ' does the file have an extension
  If InStr(objFile.Name,".") Then
    ' separate the file/extension
    strExt = LCase(Mid(objFile.Name,InStrRev(objFile.Name,".")))
    strName = Left(objFile.Name,InStrRev(objFile.Name,".")-1)
    ' is the file extension valid?
    If InStr(strValid,strExt) Then
      ' create the WME code entry for the file
      objWME.WriteLine vbTab & vbTab & "<SourceGroup Name=""" & strName & """>"
      objWME.WriteLine vbTab & vbTab & vbTab & vbTab & _
        "<Source Type=""WMENC_AUDIO"" " & _
        "Scheme=""file"" " & _
        "InputSource=""" & objFile.Path & """ " & _
        "Repeat=""no"">"
      objWME.WriteLine vbTab & vbTab & vbTab & vbTab & "<UserData ></UserData>"
      objWME.WriteLine vbTab & vbTab &vbTab & "</Source>"
      objWME.WriteLine vbTab & vbTab &vbTab & "<EncoderProfile id=""" & strGUID & """/>"
      objWME.WriteLine vbTab & vbTab & "</SourceGroup>"
    End If
  End If
Next

' end the WME code, using the intPort constant for the broadcast port
objWME.WriteLine vbTab & "</SourceGroups>"
objWME.WriteLine vbTab & "<Broadcast Http=""" & intPort & """ />"
objWME.WriteLine vbTab & "<WMEncoder_Profile id=""" & strGUID & """></WMEncoder_Profile>"
objWME.WriteLine "</WMEncoder>"

' close the WME file
objWME.Close
				

Modification Type:MajorLast Reviewed:6/23/2005
Keywords:kbinfo KB290898