2

I am trying to make a script to open up Windows movie player after a designated delay, however I cannot get windows Media Player to open up with a file passed as a parameter.

Heres what I have so far:

Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.run "WMplayer" & ""C:\Users\Public\Videos\Sample Videos\Wildlife""

I am getting an error on line 3 char 29 : Expected end of statement.

Can anyone help me? It'd be greatly appreciated.

hollopost
  • 569
  • 9
  • 28
Qinusty
  • 329
  • 2
  • 3
  • 8

3 Answers3

1
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.run "WMplayer ""C:\Users\Public\Videos\Sample Videos\Wildlife""",1,False

no need for & in between of them

OR

Dim objShell,myMedia
Set objShell = WScript.CreateObject( "WScript.Shell" )
myMedia= chr(34) & "C:\Users\Public\Videos\Sample Videos\Wildlife" & chr(34)
objShell.run "WMplayer "& myMedia &"",1,False
hollopost
  • 569
  • 9
  • 28
0

You need to quote correctly:

objShell.run "wmplayer" & ""C:\Users\Public\Videos\Sample Videos\Wildlife""

==>

objShell.run "wmplayer" & " ""C:\Users\Public\Videos\Sample Videos\Wildlife"""

Evidence:

>> WScript.Echo "wmplayer" & " ""C:\Users\Public\Videos\Sample Videos\Wildlife"""
>>
wmplayer "C:\Users\Public\Videos\Sample Videos\Wildlife"
>>

If that works from a console, it will work from your script.

For a more structured/less error prone/better scaling approach see here.

Community
  • 1
  • 1
Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96
0

If one of the command line parts is a variable, then create the whole string first, using an additional line, e.g.:

Dim objShell, commandlineString
Set objShell = WScript.CreateObject( "WScript.Shell" )
commandlineString = WMplayer & "C:\Users\Public\Videos\Sample Videos\Wildlife"
objShell.run commandlineString,1,False
WillyB
  • 1