如何从“与桌面交互”的调度程序运行Windows 2008任务 [英] How to run a Windows 2008 task from the scheduler with "interact with desktop"

查看:224
本文介绍了如何从“与桌面交互”的调度程序运行Windows 2008任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小的.NET应用程序,我通过任务计划程序在Windows 2008 Server下运行。此应用程序需要打开一个excel文件,然后将其另存为csv。当我尝试打开工作簿时,任务失败。如果我在没有任务调度程序运行的情况下手动运行它,该应用程序可以正常工作



我将其设置为以最高权限运行并选中运行天气用户已登录。



我的猜测是,这个过程需要与桌面进行交互,类似于检查服务上的与桌面交互标志。但是我已经找不到类似的事情了。



这里是失败的代码:(在工作簿上打开调用)

 code public static void ConvertExcelToCsv(string source,string destination)
{
if(File.Exists(destination))File.Delete(destination);

应用程序xl = new Application();

尝试
{
工作簿工作簿= xl.Workbooks.Open(源,类型。默认,类型。默认,类型,发送,类型。型号,型号,型号,型号,型号,型号,型号,型号,型号,型号,型号,型号,型号,型号等。
工作表ws =(Worksheet)workbook.Sheets [1];
ws.SaveAs(destination,XlFileFormat.xlCSV,Type.Missing,Type.Missing,false,false,Type.Missing,Type.Missing,Type.Missing,true);

Marshal.ReleaseComObject(ws);
}
finally
{
xl.DisplayAlerts = false;
xl.Quit();

Marshal.ReleaseComObject(xl);
}

}


解决方案

在Windows Server 2008中,Windows Server 2008中的Windows服务自动化Office有问题,尽管在Windows Server 2003下可以正常工作。此问题也发生在Open调用中,因此也可能是同样的问题。

我尝试遵循H小川在这个MSDN线程,它似乎工作。这是奇怪的,但是对Ogawa先生发现它是发现的。



小川黑客的摘要:为系统配置文件创建一个桌面文件夹,如



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



C:\Windows\System32\config\systemprofile\Desktop



...取决于您是否有64位Windows。



此外,该文件夹需要写入权限,无论用户是驾驶Office。 p>


I have a small .NET app that I'm running under Windows 2008 Server via the Task Scheduler. This application needs to open an excel file and then save it as csv. The task fails when I try to open the workbook. If I run it manually without the task scheduler running it, the app works fine.

I have it set to "Run with highest privileges" and have "Run weather user is logged on or not" checked.

My guess is that this process needs to interact with the desktop similar to check the "interact with desktop" flag on a service. But I have been unable to find a similar thing for scheduled tasks.

Here is code that is failing: (it fails on the workbook.open call)

public static void ConvertExcelToCsv(string source, string destination)
{
    if (File.Exists(destination)) File.Delete(destination);

    Application xl = new Application();

    try
    {
        Workbook workbook = xl.Workbooks.Open(source, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
        Worksheet ws = (Worksheet)workbook.Sheets[1];
        ws.SaveAs(destination, XlFileFormat.xlCSV, Type.Missing, Type.Missing, false, false, Type.Missing, Type.Missing, Type.Missing,true);

        Marshal.ReleaseComObject(ws);
    }
    finally
    {
        xl.DisplayAlerts = false;
        xl.Quit();

        Marshal.ReleaseComObject(xl);                
    }

}

解决方案

I've had problems automating Office from a Windows Service under Windows Server 2008, even though that works fine under Windows Server 2003. The problem also occurs at the Open call, so it may be the same problem.

I tried following the advice given by H Ogawa in this MSDN thread, and it seemed to work. It's bizarre, but kudos to Mr. Ogawa for discovering it.

Summary of the 'Ogawa Hack': create a desktop folder for the system profile, as either

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

C:\Windows\System32\config\systemprofile\Desktop

...depending on whether you have 64-bit Windows.

Also, the folder needs write permission for whatever user is "driving" Office.

[Edit: corrected link URL]

这篇关于如何从“与桌面交互”的调度程序运行Windows 2008任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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