例如,让 rschit 进程 Excell.exe 意味着 Perl。
问问题
234 次
2 回答
1
您是否尝试过对“taskkill /IM excel.exe”进行系统调用?
于 2010-09-22T14:10:37.950 回答
1
如果这是关于自动化后留在“服务器模式”中的过程,您可以只调用quit
应用程序对象上的方法。我在如何在使用 Perl 打开的 Excel 文件中运行宏?包括那个。(你知道,我想如果我告诉你它是一个Application
对象,你可以阅读关于那个对象的 MS 文档来弄清楚你想要做什么。)
但是,您可以使用taskkill.exe
. 您可以通过taskkill /?
在命令行上键入来阅读。它会处理taskkill /IM excel.exe
.
但是如果你想要一个特定的 PID,你需要使用tasklist.exe
. (tasklist
在命令提示符下键入以查看输出。或tasklist /?
了解更多信息。)
下面的代码同时使用:
use strict;
use warnings;
use English qw<$OS_ERROR>;
use File::Spec;
my $sys32dir = File::Spec->catfile( $ENV{SYSTEMROOT}, 'System32' );
my $tasklist_exe = File::Spec->catfile( $sys32dir, 'tasklist.exe' );
my ( $excel_line ) = grep { /^excel.exe\b/i } `$tasklist_exe`;
# $excel_line: 'EXCEL.EXE 4468 Console 1 20,968 K
# The PID is the second column
my ( undef, $pid ) = split qr{\s+}, $excel_line;
if ( my $rc = system( File::Spec->catfile( $sys32dir, 'taskkill.exe' )
, '/PID', $pid
)) {
die ( $OS_ERROR + 0 ) . ' - ' . $OS_ERROR;
}
于 2010-09-22T14:16:20.877 回答