I have a python script. It is set to run in the Microsoft Task Scheduler. When the python scripts runs from cmd or any editor it runs great. When it runs from task manager i get an error from the cscript command run from sub process. It is running as administrator, I have a variable to get the username, but I get an error can not find the file. What on earth am I doing wrong?
Python snippet:
st = 'cscript "C:\Users\Administrator\xx\xx\Visual Basic\' + vbscript + r'.vbs" 2>> ' + file result = subprocess.run(st, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
vbs:
strUser = CreateObject("WScript.Network").UserName Set xlAppl = CreateObject("Excel.Application") Set myAddIns = xlAppl.Workbooks.Open("C:Users" + strUser + "AppDataRoamingMicrosoftExcelXLSTARTxxx.xlam")
output to file when run from task manager:
`C:UsersAdministratorPROTAGONIST THERAPEUTICS, INCTran Tran – DatabaseVisual BasicFormatKnimeReport_TPO.vbs(9, 1) Microsoft Excel: Microsoft Excel cannot access the file ‘C:UsersAdministratorAppDataRoamingMicrosoftExcelXLSTARTxxx.xlam’. There are several possible reasons:
The file name or path does not exist.
The file is being used by another program.
The workbook you are trying to save has the same name as a currently open workbook.`
The file does exist, it’s the only location that it does exist, and the script runs perfectly (yes, as admin) when not run from Task Manager. I’ve packaged the python into an exe that I scheduled and same thing, runs ok from desktop and fails with same error from task manager.
I am specifying the complete path to python, and the full path to the python file in the task manager settings, the script is running OK, just the rights to the file from vbs when the cscript command is fired from the python script.
Where am I going wrong? This is driving me nuts, my thing is data and writing vbs/vba is killing me. Why is excel still a thing? Where do I set this in the firewall? Is it the firewall?
I tried a few rewrites but same results.