判断一个程序是否运行

dongyanming826 2005-10-11 09:17:18
大家好:请问,怎么判断一个程序是否正在运行啊,比如一个文档处于打开状态!谢谢!
...全文
154 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lldwolf 2005-10-14
  • 打赏
  • 举报
回复
如果只是捕获word文档的话

引用COM库“引用 Microsoft Word 9.0 Object Library”(我在此用的是Word 2000,不同的版本可能类库版本也不同)。
启动word:
Word.Application wApp = new Word.ApplicationClass();
然后在
wApp.Documents
中遍历看看有没有你需要的那个文件档好了


dongyanming826 2005-10-14
  • 打赏
  • 举报
回复
哪位兄弟说说
dongyanming826 2005-10-12
  • 打赏
  • 举报
回复
这个对单进程的管用,就是一个进程对应一个实例,现在的问题是,我想捕获一个word文档,也就是,如果我开一堆word文档,但是进程那里只有一个winword,所以我需要得到实例,不知道这个怎么搞

笑看风云,你的方法好像是检测当前运行的程序有没有被运行着
CSDNATM 2005-10-11
  • 打赏
  • 举报
回复
using System;
using System.Diagnostics;
using System.Reflection;//Assembly

namespace ShareClass
{
/// <summary>
/// 检查是否已有程序在运行
/// </summary>
public class CheckRun
{
public CheckRun()
{
//
// TODO: 在此处添加构造函数逻辑
//
}

public static Process RunningInstance()
{
Process current = Process.GetCurrentProcess();
Process[] processes = Process.GetProcessesByName (current.ProcessName);
//Loop through the running processes in with the same name

foreach (Process process in processes)
{
//Ignore the current process
if (process.Id != current.Id)
{
//Make sure that the process is running from the exe file.
if (Assembly.GetExecutingAssembly().Location.Replace("/", "\\") == current.MainModule.FileName)
{
//Return the other process instance.

return process;
}
}
}
//No other instance was found, return null.
return null;
}

}
}
yezie 2005-10-11
  • 打赏
  • 举报
回复
遍历进程,看看有没有这个进程名了
vosov 2005-10-11
  • 打赏
  • 举报
回复
写那个文档(程序),捕捉错误- -0

听楼下的

110,525

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧