杀死当前Excel进程
说明:
代码编写过程中,有时需要杀死当前Excel进程,而不影响其他Excel进程。
代码如下:
添加引用:
//杀死当前进程的API引用
using System.Runtime.InteropServices;
#region 杀死当前进程
/// <summary>
/// 杀死当前Excel 进程,不会影响其他
/// </summary>
/// <param name="excel"></param>
private static void KillProcess(Microsoft.Office.Interop.Excel.Application excel)
{
try
{
//得到这个句柄,具体作用是得到这块内存入口
IntPtr t = new IntPtr(excel.Hwnd);
int k = 0;
//得到本进程唯一标志k
GetWindowThreadProcessId(t, out k);
//得到对进程k的引用
System.Diagnostics.Process proc = System.Diagnostics.Process.GetProcessById(k);
//关闭进程k
proc.Kill();
}
catch { } } [DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int ID);
#endregion
<span style="font-size:14px;"><strong>调用:</strong></span>
//杀死Excel 进程
KillProcess(excel);
杀死当前Excel进程的更多相关文章
- 使用windows操作EXCEL如何关闭EXCEL进程
经常项目上有导入excel的需求,其实导入一个固定格式的excel数据非常容易,但是,发现一个问题就是,导入excel后,用户在打开excel时,必须要打开2次才能打开excel,这让人很不爽:开始查 ...
- Matlab使用xlsread, xlswrite函数导致excel进程无法终止的问题
系统版本:Win7 64位 Matlab版本:R2015b 问题描述:使用excel的操作函数,比如xlsread,xlswrite,导致excel进程无法终止,任务管理器中仍残留excel进程,打开 ...
- 工具类 | window批处理杀死指定端口进程
window批处理杀死指定端口进程,注意保存时使用ansi格式,运行输入端口即可 @echo off setlocal enabledelayedexpansion set /p port=请输入端口 ...
- 关闭EXCEL进程
//导入Windows类库,可以获得进程ID [DllImport("User32.dll", CharSet = CharSet.Auto)] pub ...
- C# 关闭 Excel进程
namespace ExcelTest { class DataOutput { static void Main(string[] args) ...
- C# 杀掉Windows中所有Excel进程
Process[] procs = Process.GetProcessesByName("excel"); foreach (Process pro in procs) { pr ...
- Windows系统使用vbs脚本或bat脚本强制杀死指定所有进程 vbs实现循环持续写入内容到vbs打开开的记事本 使用vbs、bat添加windows计划任务 使用cmd schtasks命令添加windows计划任务
以下脚本windows7下成功运行过,脚本也可以windows计划任务程序一起组合使用 新建一个记事本文档粘贴下面代码后将新建的记事本文档重命名下面对应的脚本名就能使用了: 添加windows计划任务 ...
- 如何监控GPU使用情况并杀死指定其中进程
仰望高端玩家的小清新 http://www.cnblogs.com/luruiyuan/ 有时候我们常常会有一个需求是监控GPU指定情况,并且需要根据需要杀死GPU进程 这里介绍几个与之相关的指令: ...
- windows下端口占用解决方法-查看和杀死占用端口进程
在Windows下启动程序时有时会遇到端口被占用的情况,由于一个端口同时只能运行一个进程,所以要想启动新的程序就要先把占用该端口的进程给kill掉,具体的命令分为以下三步, 以杀死占用了80端口的进程 ...
随机推荐
- c++ 内存泄露的检查
对于c++的内存泄露检测,除了我们自己手动检查以外,还可以使用c++中的函数来帮助我们检测, 如下代码: #include "stdafx.h" #include <stri ...
- centos 下查找软件安装在哪里的命令
linux centos 下查找软件所安装的目录在哪里 1. 如果是rpm安装的可以:rpm -ql linux(1)package-name 具体你可以man rpm 2. 可以在根目录上直接fin ...
- javascript-代码复用模式
代码复用模式 1)使用原型继承 函数对象中自身声明的方法和属性与prototype声名的对象有什么不同: 自身声明的方法和属性是静态的, 也就是说你在声明后,试图再去增 ...
- POJ 1961 Period(KMP)
http://poj.org/problem?id=1961 题意 :给你一个字符串,让你输出到第几个字符时,循环结的个数. 思路 :这个题和2409差不多,稍微修改一下,加一个循环就行了,用的也是K ...
- 处理MySQL数据库出现大量Locked的一个案例 (转)
本文转自:http://blog.itpub.net/7607759/viewspace-696781/ 做为一款轻量级数据库软件,MySQL在使用过程中遇到访问速度慢,或者无法响应这类的问题,解决方 ...
- c/c++ 重载 数组 操作符[] operator[ is ambiguous, as 0 also mean a null pointer of const char* type.
// Note: //int x = a[0].GetInt(); // Error: operator[ is ambiguous, as 0 also mean a null pointer of ...
- Pascal Game Development with Jason McMillen
In this much belated episode I talk with Jason McMillen of Pascal Game Development. We discuss the s ...
- codeigniter 分页类练习
controller page页: <?php class Blog extends CI_Controller{ public function __construct(){ parent:: ...
- oracle删除列
ALTER TABLE 表名 DROP COLUMN 列名;
- Linux Kernel ‘mp_get_count()’函数本地信息泄露漏洞
漏洞名称: Linux Kernel ‘mp_get_count()’函数本地信息泄露漏洞 CNNVD编号: CNNVD-201311-054 发布时间: 2013-11-06 更新时间: 2013- ...