在命令提示符下使用TASKKILL(批次) [英] Using Taskkill in command prompt (Batch)

查看:192
本文介绍了在命令提示符下使用TASKKILL(批次)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有4个Excel文件(city.xls,rule.xls,adv.xls和maping.xls),所有的Excel文件被打开。如何强制关闭只有一个文件(例如:maping.xls)?在批量使用taskkill / CMD编程

i have 4 excel files (city.xls, rule.xls,adv.xls and maping.xls), where all of excel files being opened. how to force close only one file (Ex: maping.xls) with taskkill in batch/CMD programing?

推荐答案

TASKKILL将消除所有窗口的过程。您的工作簿可以是Excel中的同一个实例下的所有开放的,所以,使用taskkill不能做你所需要的。

Taskkill will eliminate a process with all its windows. Your workbooks can be all open under the same instance of excel, so, taskkill can not do what you need.

您可以使用一些工具,如AutoIt的,的NirCmd,cmdow,......只是关闭您需要的窗口,但你将不得不处理对话框posibility询问是否保存工作簿。

You can use some tools like AutoIt, nircmd, cmdow, ... to just close the window that you need, but you will have to deal with the posibility of dialog asking to save the workbook.

下面是一个批处理文件(只保存为的.cmd和更改XLSX文件)至极包括脚本的一部分来搜索该工作簿并关闭它没有对话。没有bulleproof,仅能打开该工作簿,而只是一个起始样品的用户的同一个会话下。

Here is a batchfile (just save as .cmd and change the xlsx file) wich includes a script part to search the workbook and close it without dialogs. No bulleproof, and only works under the same session of the user that opened the workbook, but just a starting sample.

@if (@This==@IsBatch) @then
@echo off
rem **** batch zone *********************************************************

    rem call javascript part of batch file
    cscript //nologo //e:Javascript "%~dpnx0" /workbook:"j:\wherever\myWorkbook.xlsx"

    rem End of batch area. Ensure batch ends execution before reaching
    rem javascript zone
    exit /b

@end
// **** Javascript zone *****************************************************

    if (!WScript.Arguments.Named.Exists('workbook')) {
        // if no workbook argument, no work to do
        WScript.Quit(1);
    };

    // retrieve workbook name
    var workbook = WScript.Arguments.Named.Item('workbook');

    var exitCode = 0;
    try {
        // search for workbook application
        var wb = GetObject(workbook);

        // get handle to application containing workbook
        var app = wb.Application;

        // close workbook. Ask for save = false
        wb.Close( false );

        // if no more workbooks open in application, close it
        if (app.Workbooks.Count == 0){ 
            app.Quit();
        };

    } catch(e){
        // some kind of problem with objects
        // WScript.Echo( e.description );
        exitCode = 2;
    };
    app =null;
    wb  =null;
    WScript.Quit(exitCode);

这篇关于在命令提示符下使用TASKKILL(批次)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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