ActiveXObject(Excel)在Procces <Javascript>中保留EXCEL.EXE * 32

var Excel = new ActiveXObject('Excel.Application'); Excel.Visible = false; var Excel_file = Excel.Workbooks.Open(Worksheet); } if(x == 2) { Excel_file.close(false); Excel.Quit(); Excel.Application.Quit(); Excel = null; Excel_file = null; window.setTimeout(CollectGarbage, 10); //Excel.DisplayAlerts = false; } 

Windows任务pipe理器显示

我使用ActiveXObject在幕后打开Excel应用程序,执行我的function(在别处定义和调用),然后closures它。 问题是,通过任务pipe理器,每次运行该程序时,都会在进程部分创build一个新的EXCEL.EXE * 32实例。

这个脚本在网页上,它将在整个一天经常运行。 每次程序运行时创build一个不同的实例是不可行的。

我尝试使用其他人推荐的无证“CollectGarbage”,但仍不能解决问题。

有任何想法吗? 谢谢。

您可以使用相同的activex对象在任务pipe理器中终止任务。 试试下面

 var WshShell = new ActiveXObject("WScript.Shell"); var oExec = WshShell.Exec("taskkill /F /IM EXCEL.exe"); 

TASKKILL

结束一个或多个进程(按进程ID或图像名称)。

语法TASKKILL [/ S system [/ U username [/ P [password]]]] {[/ FI filter] [/ PID processid | / IM imagename]} [/ F] [/ T]

选项/ S系统连接到的远程系统。

 /U [domain\]user The user context under which the command should execute. /P [password] The password. Prompts for input if omitted. /F Forcefully terminate the process(es). /FI filter Display a set of tasks that match a given criteria specified by the filter. /PID process id The PID of the process to be terminated. /IM image name The image name of the process to be terminated. Wildcard '*' can be used to specify all image names. /T Tree kill: terminates the specified process and any child processes which were started by it. 

filter应用下面的filter之一:

  Imagename eq, ne String PID eq, ne, gt, lt, ge, le Positive integer. Session eq, ne, gt, lt, ge, le Any valid session number. Status eq, ne RUNNING | NOT RESPONDING CPUTime eq, ne, gt, lt, ge, le Time hh:mm:ss MemUsage eq, ne, gt, lt, ge, le Any valid integer. Username eq, ne User name ([Domain\]User). Services eq, ne String The service name Windowtitle eq, ne String Modules eq, ne String The DLL name