这段代码的作用是找到所有打开的winword程序(不是进程),然后关闭掉。
using System;
using System.Runtime.InteropServices;
using Word; //Add Com Reference: Microsoft Word 10.0 Object Library
namespace CloseDocSample
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//Define parameter value for winword
object oMissing = System.Reflection.Missing.Value;
//Find the exist winword application
Word.Application winObj = (Word.Application)Marshal.GetActiveObject("Word.Application");
//Close the application
winObj.Quit(ref oMissing, ref oMissing, ref oMissing);
//Release object
System.Runtime.InteropServices.Marshal.ReleaseComObject(winObj);
winObj = null;
}
}
}
找到所有打开的winword程序(不是进程),然后关闭掉。
最新推荐文章于 2018-10-25 17:33:38 发布