如何判断另外一个进程 是否正在运行

zhangpuwei 2008-04-28 09:18:09
各位大侠,在.net中,
my.exe中,如何判断名字为xxx.exe的程序是否在运行?
谢谢。
...全文
140 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
herol 2008-04-28
  • 打赏
  • 举报
回复

Dim current As Process

Try
current = Process.GetCurrentProcess
Dim processes As Process() = Process.GetProcessesByName(current.ProcessName)

'查找相同名的进程
Dim tmpProcess As Process

For Each tmpProcess In processes
'忽略当前进程
If tmpProcess.Id <> current.Id Then
'确认相同名的进程运行位置是否相同
If Reflection.Assembly.GetExecutingAssembly().Location.Replace("/", "\") = current.MainModule.FileName Then
'返回其它的运行实例
Return tmpProcess
End If
End If
Next tmpProcess
'没有其它实例,返加空值
Return Nothing
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
End
Finally

End Try


这是判断本进程是否在运行,想判断其他进程,就把进程名改成想判断的进程就行了
水如烟 2008-04-28
  • 打赏
  • 举报
回复
不能单从文件名xxx.exe来判断,要从进程名称来判断.因为文件名是可以修改的.

16,717

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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