比如说我想写个程序,当每次"Winamp.exe"运行时候ShowMessage("Winamp已经运行")(只显示一次),关掉winamp再运行还是显示这句话~
解决方案 »
- 请教一个问题:为什么WinMain()用GetMessage()取得消息后要将消息再用Dispatch给Windows呢?
- 我感冒了 咳嗽 难受啊 杂办
- 请教在MFC里面获得系统时间的格式问题
- 删除的时候要选择datagrid中时候,如何进行删除啊??
- 怎样使用发送消息的方式实现CListBox的AddString()方法,就像使用发送WM_SETTEXT消息可以调用CWnd的SetWindowText()那样。。。。
- GetSafeHdc() 的含义及用法
- 关于BSTR数据类型的几个问题
- 控制台程序和数据库的问题?
- 大家知道dll是有Export的。但是我用exeScope分析时发现,有的exe也有export,例如IpSniper的Export里赫然有一个OicqDebug.Exe,但是有的Exe又没有export。请问这是怎么回事?
- 【求助】VS2010 的MSDN 用H3Viewer 索引不全
- 如何使Static控件中的文本自动换行
- 编译提示重复定义了,大家看看怎么办LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in msvcrtd.lib(cinitexe.obj)
能不能给出具体参数和用法,偶是新人~~~谢谢了
hProSnap=CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
if (::Process32First(hProSnap,&ProInfo))
{
for (;::Process32Next(hProSnap,&ProInfo);)
{
if (strcmp(ProInfo.szExeFile, "Winamp.exe") == 0)
{
AfxMessageBox("Winamp已经运行");
break;
}
}
}
需要用到"tlhelp32.h"头文件
使用脚本如下,也可以使用COM接口,不过稍微麻烦一点。
Monitor Process Creation
Description
Temporary event consumer that issues an alert each time a new process is created. Script Code strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colMonitoredProcesses = objWMIService. _
ExecNotificationQuery("select * from __instancecreationevent " _
& " within 1 where TargetInstance isa 'Win32_Process'")
i = 0
Do While i = 0
Set objLatestProcess = colMonitoredProcesses.NextEvent
Wscript.Echo objLatestProcess.TargetInstance.Name
Loop将上述脚本存为.vbs文件,双击执行。
当每次"Winamp.exe"运行时候ShowMessage("Winamp已经运行")(只显示一次),关掉winamp再运行还是显示这句话~将下面的代码存为temp.vbs,双击运行就可以了(本例子使用的是notepad.exe,你自己修改成你需要的)
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colMonitoredProcesses = objWMIService. _
ExecNotificationQuery("select * from __instancecreationevent " _
& " within 1 where TargetInstance isa 'Win32_Process' and TargetInstance.Name = 'notepad.exe'")
i = 0
Do While i = 0
Set objLatestProcess = colMonitoredProcesses.NextEvent
Wscript.Echo objLatestProcess.TargetInstance.Name
Loop你在VC中可以新建立一个进程(CreateProcess)运行这个进程 cscript temp.vbs你也可以使用COM接口,但是比较繁琐,具体的参看MSDN中关于WMI的部分。使用CreateToolhelp32Snapshot是不是需要轮循,我没有做过