0

I'm new and have never done any coding or scripting in my life before and I'm trying to make a batch file that will...

  • check to see if itunes is running
  • if it is running, open a vbs file for my playlist
  • if it is not running, open itunes
  • wait 30 seconds
  • recheck again until it is able to launch the vbs
  • then stop checking

I'm planning on putting this in my startup folder so that when I open my computer up it will start playing music from the start...

But having no coding experience whatsoever I've pretty much only been able to Google search other peoples' solutions and try them blindly in hopes that they work...

so far ive found and tried

@echo off

PATH=C:\Program Files\iTunes\iTunes.exe

iTunes.EXE YourProgram.exe >nul

if ERRORLEVEL 1 goto Process_NotFound

:Process_Found

echo iTunes is running

goto END

:Process_NotFound

echo iTunes is not running

Itunes.exe

goto END

:END

--

@echo off      
tasklist /FI "IMAGENAME eq iTunes.exe" | find /i "iTunes.exe"      

IF ERRORLEVEL 2 GOTO LOOP2
IF ERRORLEVEL 1 GOTO LOOP1 

:LOOP1 
  start notepad.exe
goto EXIT     

:LOOP1 
  start iTunes.exe 
goto EXIT 

:EXIT

And

tasklist /FI "IMAGENAME eq iTunes.exe" /FO CSV > search.log

FOR /F %%A IN (search.log) DO IF %%~zA EQU 0 GOTO end

start iTunes.exe

:end

When I test them, the first bat does nothing at all, the second one just opens a blank notepad whether or not iTunes is running, and the third saves a text file to my desktop named "search" and depending on whether iTunes is running or not it changes what search has inside.

INFO: No tasks are running which match the specified criteria.
  • If iTunes is off

And

"Image Name","PID","Session Name","Session#","Mem Usage"
"iTunes.exe","7208","Console","1","105,512 K"
  • If iTunes is running

It seems this last one is the closest to what I need but I still have no idea how to alter that and change it to what I need.

Can you guys help me out here?

| improve this question | | | | |
  • I suggest you check out our arqade community. – RookieTEC9 Oct 28 '15 at 22:44
0

Try a simple batch script like the below. I'm not sure what your VB script is but if you show me the logic, I'll add to this script so can be launched with the batch script. . .

This should do exactly what you listed but clarify the VB script stuff for me and I'll add that; sounds rather simple. . .

1. Check if iTunes is running in memory (if running then do #3)

2. Start iTunes if it's not running and then wait 30 seconds and check that it's running in memory again

3. Check that iTunes is running in memory, and if it is, go to the VB Script routine to kick that off for your playlist, etc. and then end the script.

@ECHO OFF

:CheckiTunesRunning
TASKLIST | FINDSTR /I "iTunes.exe"
IF ERRORLEVEL 1 (GOTO StartiTunes) ELSE (GOTO OpenPlayList)

:StartiTunes
START "iTunes" "C:\Program Files\iTunes\iTunes.exe"
::: 30 second pause
PING -n 30 127.0.0.1 > nul
GOTO CheckiTunesRunning

:OpenPlayList
<Open PlayList Logic VB, etc.>
GOTO EOF
| improve this answer | | | | |
  • 1
    :D This one works! I slapped in a simple doodad to open my playlist and put EOF as "exit" and now it works! Sure it takes two minutes before it completes fully, but so does everything else on my PC at startup! – xtreemgamer129 Oct 29 '15 at 0:25
0

Your second code

@echo off      
tasklist /FI "IMAGENAME eq iTunes.exe" | find /i "iTunes.exe"      
IF ERRORLEVEL 2 GOTO LOOP2
IF ERRORLEVEL 1 GOTO LOOP1 
:LOOP1 
start notepad.exe
goto EXIT     
:LOOP1 
start iTunes.exe 
goto EXIT 
:EXIT

You have two :LOOP1, so you will always get the first one to start notepad.exe. There is no :LOOP2 for it to go to so when it reads "GOTO LOOP2" it won't find it and continue down the lines, then it finds LOOP1, starts notepad, then goes to EXIT.

@echo off      
tasklist /FI "IMAGENAME eq iTunes.exe" | find /i "iTunes.exe"      
IF ERRORLEVEL 2 GOTO LOOP2
IF ERRORLEVEL 1 GOTO LOOP1 
:LOOP2
start notepad.exe
goto EXIT     
:LOOP1 
start iTunes.exe 
goto EXIT 
:EXIT

Your third code with

tasklist /FI "IMAGENAME eq iTunes.exe" /FO CSV > search.log

the /FO CSV > search.log

is for [File-Output] [CSV] [saved to] [search.log]

I used the [] to show each syntax and what it does.

| improve this answer | | | | |
0

The second sample provided does go in the right direction. Though there are a couple of mistakes that I've found.

  • You have written down LOOP1 twice, instead of LOOP1 followed by LOOP2. Try using more unique names to avoid this.
  • findstr returns errorlevel 0 when the string has been found, errorlevel 1 if it hasn't. You can check this by using ECHO %errorlevel% within your batch file.

Hopefully the following example will help you expand this further.

tasklist.exe | findstr "iTunes.exe"

IF ERRORLEVEL 1 GOTO NOTFOUND
IF ERRORLEVEL 0 GOTO RUNNING

:RUNNING
ECHO "Application is running, replace this line with the code you want"  
GOTO END

:NOTFOUND
ECHO "Application not found, replace this line with the code you want"
GOTO END

:END
| improve this answer | | | | |
  • @CanadianLuke Thanks! Expanded the script a little to make it more clear, left out some things because it was an example. Will give that article a read though. – Quietus Oct 28 '15 at 21:00
  • Well like I said in the main post, I didn't write any of the examples I showed. I only found those while trying to google search my way to the solution because I have about the IQ level of a potato. – xtreemgamer129 Oct 28 '15 at 22:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.