从任务计划程序启动时,应用程序引发错误 [英] Application throws an error when launched from task scheduler

查看:140
本文介绍了从任务计划程序启动时,应用程序引发错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义应用程序,该应用程序使用Microsoft.Office.Interop.Excel.Application打开并保存excel文件.我有一批可以使用所有必需参数触发应用程序的批处理.手动运行时,该批次成功完成了任务,但是当我尝试在任务计划程序中计划该任务时,我从ma应用程序中记录了以下错误消息:

I have a custom application which uses Microsoft.Office.Interop.Excel.Application to open and save excel file. I have a batch which fires the app with all the required parameters. That batch completes the task successfully when run manually but when I tried to schedule the same in task scheduler I got the following error msg logged from ma app:

Microsoft Office Excel无法访问文件 'E:\ tasks \ extractSPdocs \ downloads \ Last_Minute_IT_DATA_DUMP_201404250000.xls'. 有几种可能的原因:

Microsoft Office Excel cannot access the file 'E:\tasks\extractSPdocs\downloads\Last_Minute_IT_DATA_DUMP_201404250000.xls'. 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.

我知道以下代码部分引发了错误:

I know the error is thrown from the following code section:

 try
                        {
                            excelfile = new Microsoft.Office.Interop.Excel.Application();
                            excelfile.DisplayAlerts = false;
                            var wb = excelfile.Workbooks.Open(dirpath + "\\" + csvname);
                            wb.SaveAs(dirpath + "\\" + csvname.Substring(0, csvname.LastIndexOf('.')), Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook);
                            csvname = csvname.Substring(0, csvname.LastIndexOf('.')) + ".xlsx";
                            csvext = ".xlsx";
                        }

该任务是使用与我使用的相同帐户创建的(本地管理员). 它设置为以最高特权运行,并从批处理文件目录开始. 操作系统是Windows Server 2008.

The task is created with the same account I am using (local admin). It is set to run with highest privileges and to start in the batch file directory. The OS is Windows Server 2008.

我不知道为什么这会失败,但是怀疑这与调度程序启动我的应用程序,然后启动Excel的上下文有关.有人可以提出解决方案吗?

I do not know why this is failing but suspect this has something to do with the context in which the scheduler launches my application which then subsequently launches Excel. Can anybody suggest a solution?

推荐答案

我在这里找到了解决方法

I have found a solution here http://justgeeks.blogspot.co.uk/2012/10/troubleshooting-microsoft-excel-cannot.html

诀窍是您必须将这个文件夹放到烤架上

the trick is you have to craete this folder:

C:\ Windows \ SysWOW64 \ config \ systemprofile \ Desktop

我必须承认,我不太了解为什么任务计划程序启动Excel时需要此文件夹才能打开文件,但是它可以工作.

I must admit I do not quite understand why this folder is required for excel to open files when launched by task scheduler but it works.

这篇关于从任务计划程序启动时,应用程序引发错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆