Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fix My VBScript

Status
Not open for further replies.

TodTown

Technical User
Apr 19, 2018
2
US
I have this vbscript that I copied from an online source. It starts the Spotify application on my desktop and begins playing the specified playlist. I can double-click the vbs file from Windows Explorer and it works just fine. I created a scheduled task to run the script. When I attempt to run the scheduled task a Windows dialog appears asking How do you want to open this file?

Here's the vbscript code with my comments added:

Set WshShell = WScript.CreateObject("WScript.Shell")
'This is the path to the Windows Spotify application. (I realize that they've misspelled CommandLine, but it works spelled this way for some reason)
Comandline = "C:\Users\Tod\AppData\Local\Microsoft\WindowsApps\Spotify.exe"
WScript.sleep 500
'The argument to the Run method is the playlist within the Spotify application to run
CreateObject("WScript.Shell").Run("spotify:user:todtown:playlist:4zFrHtT8bSgXIltkkiScMk")
WScript.sleep 3000
WshShell.SendKeys " "

My scheduled task simply says:
"C:\Users\Tod\Load Spotify.vbs"
With no arguments

Can anyone suggest changes to either the script or the scheduled task, or other suggestions that I can try?

tod
 
>I realize that they've misspelled CommandLine, but it works spelled this way for some reason

Because the script does not then subsequently use this, and because ComandLine here is just a variable name, it could have been anything, so a spelling error is not necessarily an issue anyway.

>Can anyone suggest changes to either the script or the scheduled task

Unfortunately cannot replicate your problem, my version of the script works fine from the task scheduler (on Windows 10)

Code:
[blue]Set WshShell = WScript.CreateObject("WScript.Shell")
[green]'The argument to the Run method is the playlist within the Spotify application to run[/green]
CreateObject("WScript.Shell").Run("spotify:user:todtown:playlist:4zFrHtT8bSgXIltkkiScMk")
WScript.sleep 3000 [green]'On slower systems you may need to increase this delay, as it allows Spotify to open properly[/green]
WshShell.SendKeys " "[/blue]
 
Thanks strongm for the reply. I was suspicious of those first two line of my script. Didn't seem like they were being used for anything. I solved the problem by modifying my scheduled task. Now the task opens wscript.exe and the argument is the path to the vbscript file. That worked perfectly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top