检查应用程序是否正在运行(Check If Application Is Running)

   IT问题网   2021-02-20 00:00:00

问 题

有没有办法运行一个循环来检查应用程序是否正在运行?到目前为止我有这个。它在windows控制台程序中。我正在使用visual studio 2010.它的定义是_afxdll。



  #include   "  stdafx.h" 
#include lt; afx.h gt;
int main()
{
handle hd;
lpcwstr mu =(lpcwstr)" 记事本";
hd = createmutex(null,false,mu);
if (getlasterror()== error_already_exists)
{
// messagebox :: show("程序已在运行。");
return 1 ;
}
closehandle(hd);

解决方案

使用此:



am只是硬编码并比较是否正在运行internet.exe!

这样你就可以动态地确定任何正在运行的服务。你也可以从命令行传递参数。
 






 #include"afxwin.h"
#includelt; wtsapi32.hgt;
#includelt; iostreamgt;

#pragma comment(lib,"wtsapi32.lib")

using namespace std;

dword pcount = 0;
pwts_process_info ppprocessinfo,pprocess;
wtsenumerateprocesses(wts_current_server_handle,0,1,amp; ppprocessinfo,amp; pcount);
pprocess = ppprocessinfo;
cstring internet ="iexplore.exe";

for(int i = 0; ilt; pcount; i ++)
{
pprocess-gt; pprocessname;
if(internet.comparenocase(pprocess-gt; pprocessname)== 0)
{
coutlt;lt; "iexplore运行";
}
pprocess ++;
}lt; / iostreamgt;lt; /wtsapi32.hgt;

您可以使用wmi监视任何进程并获取有关系统事件的通知到创建和终止等过程。请参阅此codeproject文章:使用wmi处理信息和通知 [ ^ ]。



-sa

标签:检查应用程序是否是不是正在运行



分享:

  • 微信
  • QQ好友
  • QQ空间
  • 新浪微博


热门推荐

如何使用radiobuttonlist?(how to use radiobuttonlist)

problem i want to write select query for selectedindexcha ...

如何计算日期差异和数字差异(How to Calculate Date Diff And Num Diff)

problem glnotranscationdate deposit withdraw transid loan ...

ie6浏览器问题在我的网页上(ie6 browser issue in my web page)

problem my webpage displaying 1 inleft bottom corner only ...

无法在表单上使用控件。(Unable to use controls on the form.)

problem hi, i have created some static insta ...

如何在Javascript中使用正则表达式匹配定义的模式(How to match defined pattern using regular expression in Javascript)

problem hi, first, there is a string called: var bookpat ...

我想打印收据,但我遇到了问题(I want to print a reciept but i face a problem)

problem in this project i am using datareport ...

Visual Studio 2010 + Windows 7 + 64位计算机+ C ++ + 32位DLLS = 3个问题(Visual Studio 2010 + Windows 7 + 64-bit computer + C++ + 32 bit DLLS = 3 problems)

problem i''ve been using visual studio 2005 for many year ...

什么是Eclipse以及如何使用它?(What is about Eclipse and how to use it)

problem how to use it .and for what purpose it is used so ...

如何从数据库中检索数据?(how to retrieve data from database)

problem i have a radiobuttonlist control and i want to re ...

使用SQL Management Studio将数据插入我的数据库时执行NonQuery(ExecuteNonQuery while inserting the data into my database using SQL Management Studio)

problem hi i have a problem while inserting the data int ...

我如何将C#.Net中的拖放图像转换为ASP.Net(how do i convert Drag and drop image in C#.Net to ASP.Net)

problem hi, i saw the drag and drop image in c#.net arti ...

如何禁用浏览器的后退按钮(How to disable browser's back button)

problem hello friend, i am using asp.net framework 3.5,i ...

滚动后无法打印文本....(Unable to print text after scrolling....)

problem hi, i have written a small c program ...

我使用radgrid,我从数据库获取列名,但我希望他们的名称作为不同的名称,如何重命名RadGrid的列名(Im using a radgrid ,i get column names from database but i want their names as diferent names,How to rename those columns names of RadGrid)

problem im using a radgrid ,i get column names from datab ...

用于showbits函数的头文件(header file to be used for showbits function)

problem which header file shd be used for showbits() func ...

在gridview控件中删除事件行。(Row Deleting event in gridview control.)

problem i am trying to delete userid and groupid from the ...

如何查看.dll文件中编写的代码?(how to view code written in .dll file)

problem hi to all.i have downloaded source co ...

登录 - 使用哈希值检查密码(login - check password with hashed one)

problem this is my code to hash class hashin ...

上传图片时出现问题(problem in uploading images)

problem i want to upload images that will be saved in a f ...

如何使用c#向Bixolon热敏打印机发送命令(How to Send commands to Bixolon thermal printer using c#)

problem first of all , i have searched on goo ...