import os
import subprocess

def getTasks(names):
    foundNames = []
    for n in range(len(names)):
        foundNames.append('notFound')
    f = 0
    tasks = os.popen('tasklist /v').read().strip().split('\n')
#    print ('# of tasks is %s' % (len(tasks)))
    for i in range(len(tasks)):
        for n in range(len(names)):
            if names[n] in tasks[i]:
                foundNames[n]=names[n]
 #       print(tasks[i])
    return foundNames

if __name__ == '__main__':
    names = ['VIMS Interface Uploads','DayTarget']
    shortcuts = ['c:/Users/vimsadmin/Desktop/VIMS Interface Uploads.lnk','c:/Users/vimsadmin/Desktop/Daily Target Upload.url']

# restart massing tasks
    tasks = getTasks(names)
    for i in range(len(names)):
        if i >= len(tasks) or names[i] != tasks[i]:
#            print(names[i], 'is NOT running')
            try:
                os.startfile (shortcuts[i])
            except Exception as err:
                pass
#    print('Running-',r)

#    if not r:
#        print('%s - No such process' % (imgName)) 

#    elif 'Not Responding' in r:
#        print('%s is Not responding' % (imgName))
        
#    else:
#        print('%s is Running' % (imgName))