AndyDookie
Technical User
I do volunteer work for a community Radio Station and need some help with vbscript to read from a users editable config file into my script. Script is to load any music player stall for a determined time before running "ZaraRadio" an automated playout program. Zara needs the audio drivers loaded by any other player as it does not have drivers for our MAudio Delta 44 sound card.
My config file:
#Hash lines are comment lines
#You may add as many hash lines as you want
AMusicProg="""C:\Program Files\Windows Media Player\wmplayer.exe"""
ASongToPlay="""D:\My Documents\Andrew\LimeWire Files\Surfing Music\Surf Music ver2.mp3"""
SleepTime=5000
strProcessKill=("""wmplayer.exe""")
#End of the configuration file
My script so far. It fails to load the player
And I need a routine to kill the exact player in the config file as it may change for different studios.
Any help would be appreciated.
script:
Option Explicit
DIM FSO: SET FSO = CreateObject ("Scripting.FileSystemObject")
'Declare the variables to be used from the property file
DIM AMusicProg, ASongToPlay,SleepTime, strProcessKill
Dim objWMIService, objProcess, colProcess
Dim strComputer, WshShell 'dim and allocate ZaraProgTarget = """Somewhwere\zara.exe"""
strComputer = "."
SetConfigFromFile("D:\My Documents\Andrew\VBFiles\Practice\zaraconfig.txt") 'read in zaraconfig.txt
msgbox "AMusicProg=" & AMusicProg
'msgbox "ASongToPlay=" & AMusicProg
'msgbox "SleepTime=" & SleepTime
'msgbox "strProcessKill =" & strProcessKill
'AMusicProg=("""C:\Program Files\Windows Media Player\wmplayer.exe""") 'could be any player
'ASongToPlay = """D:\My Documents\Andrew\LimeWire Files\Surfing Music\Surf Music ver2.mp3""" 'any song can be used!
set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run (AMusicProg) '& ASongToPlay, 4
'SleepTime = 5000
'Wscript.Sleep SleepTime 'fiddle sleep for time for Zara's drivers to load
strProcessKill = (" 'wmplayer.exe' ") '********** could be QuickTime?
' *************Insert Zara.exe here ***********************
'WshShell.Run ZaraProgTarget, 3
searchforapps 'cheack all running apps
terminateprogram 'kill strProcessKill = "'wmplayer.exe'" '********** could be QuickTime?
WSCript.Echo "Just killed process " & strProcessKill _
& " on " & strComputer
WSCript.Quit 'Empty ram of wscript
'---------------------------------Get Variables from ZaraConfig.txt------------------------
Sub SetConfigFromFile(fileName)
DIM strConfigLine,fConFile,EqualSignPosition, strLen, VariableName, VariableValue
SET fConFile = fspenTextFile(fileName)
WHILE NOT fConFile.AtEndOfStream
strConfigLine = fConFile.ReadLine
strConfigLine = TRIM(strConfigLine)
'msgbox(strConfigLine)
IF (INSTR(1,strConfigLine,"#",1) <> 1 AND LEN(strConfigLine) <> 0) THEN
EqualSignPosition = INSTR(1,strConfigLine,"=",1)
strLen = LEN(strConfigLine)
VariableName = LCASE(TRIM(MID(strConfigLine, 1, EqualSignPosition-1))) 'line 34
VariableValue = TRIM(Mid(strConfigLine, EqualSignPosition + 1, strLen - EqualSignPosition))
SELECT CASE VariableName
'ADD EACH OCCURRENCE OF THE CONFIGURATION FILE VARIABLES(KEYS)
CASE LCASE("AMusicProg")'
IF VariableValue <> "" THEN AMusicProg = VariableValue
CASE LCASE("ASongToPlay")'
IF VariableValue <> "" THEN ASongToPlay = VariableValue
CASE LCASE("SleepTime")'
IF VariableValue <> "" THEN SleepTime = VariableValue
CASE LCASE("strProcessKill")'
IF VariableValue <> "" THEN strProcessKill = VariableValue
END SELECT
END IF
WEND
fConFile.Close
End Sub '------------------------------------------------------------------------
'--------------------------cheack all running apps----------------------------------------
sub searchforapps()
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
end sub
'------------------------------kill strProcessKill from all running apps=** could be QuickTime?----------------------
sub terminateprogram()
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcessKill )
For Each objProcess in colProcess
objProcess.Terminate()
Next
end sub
'-------------------------------------------------------------------------------------------------
My config file:
#Hash lines are comment lines
#You may add as many hash lines as you want
AMusicProg="""C:\Program Files\Windows Media Player\wmplayer.exe"""
ASongToPlay="""D:\My Documents\Andrew\LimeWire Files\Surfing Music\Surf Music ver2.mp3"""
SleepTime=5000
strProcessKill=("""wmplayer.exe""")
#End of the configuration file
My script so far. It fails to load the player
And I need a routine to kill the exact player in the config file as it may change for different studios.
Any help would be appreciated.
script:
Option Explicit
DIM FSO: SET FSO = CreateObject ("Scripting.FileSystemObject")
'Declare the variables to be used from the property file
DIM AMusicProg, ASongToPlay,SleepTime, strProcessKill
Dim objWMIService, objProcess, colProcess
Dim strComputer, WshShell 'dim and allocate ZaraProgTarget = """Somewhwere\zara.exe"""
strComputer = "."
SetConfigFromFile("D:\My Documents\Andrew\VBFiles\Practice\zaraconfig.txt") 'read in zaraconfig.txt
msgbox "AMusicProg=" & AMusicProg
'msgbox "ASongToPlay=" & AMusicProg
'msgbox "SleepTime=" & SleepTime
'msgbox "strProcessKill =" & strProcessKill
'AMusicProg=("""C:\Program Files\Windows Media Player\wmplayer.exe""") 'could be any player
'ASongToPlay = """D:\My Documents\Andrew\LimeWire Files\Surfing Music\Surf Music ver2.mp3""" 'any song can be used!
set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run (AMusicProg) '& ASongToPlay, 4
'SleepTime = 5000
'Wscript.Sleep SleepTime 'fiddle sleep for time for Zara's drivers to load
strProcessKill = (" 'wmplayer.exe' ") '********** could be QuickTime?
' *************Insert Zara.exe here ***********************
'WshShell.Run ZaraProgTarget, 3
searchforapps 'cheack all running apps
terminateprogram 'kill strProcessKill = "'wmplayer.exe'" '********** could be QuickTime?
WSCript.Echo "Just killed process " & strProcessKill _
& " on " & strComputer
WSCript.Quit 'Empty ram of wscript
'---------------------------------Get Variables from ZaraConfig.txt------------------------
Sub SetConfigFromFile(fileName)
DIM strConfigLine,fConFile,EqualSignPosition, strLen, VariableName, VariableValue
SET fConFile = fspenTextFile(fileName)
WHILE NOT fConFile.AtEndOfStream
strConfigLine = fConFile.ReadLine
strConfigLine = TRIM(strConfigLine)
'msgbox(strConfigLine)
IF (INSTR(1,strConfigLine,"#",1) <> 1 AND LEN(strConfigLine) <> 0) THEN
EqualSignPosition = INSTR(1,strConfigLine,"=",1)
strLen = LEN(strConfigLine)
VariableName = LCASE(TRIM(MID(strConfigLine, 1, EqualSignPosition-1))) 'line 34
VariableValue = TRIM(Mid(strConfigLine, EqualSignPosition + 1, strLen - EqualSignPosition))
SELECT CASE VariableName
'ADD EACH OCCURRENCE OF THE CONFIGURATION FILE VARIABLES(KEYS)
CASE LCASE("AMusicProg")'
IF VariableValue <> "" THEN AMusicProg = VariableValue
CASE LCASE("ASongToPlay")'
IF VariableValue <> "" THEN ASongToPlay = VariableValue
CASE LCASE("SleepTime")'
IF VariableValue <> "" THEN SleepTime = VariableValue
CASE LCASE("strProcessKill")'
IF VariableValue <> "" THEN strProcessKill = VariableValue
END SELECT
END IF
WEND
fConFile.Close
End Sub '------------------------------------------------------------------------
'--------------------------cheack all running apps----------------------------------------
sub searchforapps()
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
end sub
'------------------------------kill strProcessKill from all running apps=** could be QuickTime?----------------------
sub terminateprogram()
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcessKill )
For Each objProcess in colProcess
objProcess.Terminate()
Next
end sub
'-------------------------------------------------------------------------------------------------