Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Command5_Click()
Dim lHwnd As Long
lHwnd = FindWindow(vbNullString, "程序的Title或Caption")
If lHwnd <>0 Then
MsgBox "程序正在运行!"
End If
End Sub
向它发送指令:
AppActivate "程序的Title或Caption"
SendKeys "指令橘逗"
要启动程序:圆历卖
Call Shell("完整路径烂中和程序名称.exe")
#include "windows.h"#include "tlhelp32.h"
int GetProcessCount(const char* szExeName)
{
char sztarget[MAX_PATH]
HANDLE l
int count = 0
PROCESSENTRY32 my
lstrcpy(sztarget, szExeName)
CharLowerBuff(sztarget, MAX_PATH)
l = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
if (((int)l) != -1)
{
my.dwSize = sizeof(my)
if (Process32First(l, &my))
{
do
{
CharLowerBuff(my.szExeFile, MAX_PATH)
if (lstrcmp(sztarget, my.szExeFile) == 0)
{
count++
}
}while (Process32Next(l, &my))
}
CloseHandle(l)
}
return count
}
函数 GetProcessCount(szExeName) 返回 szExeName 指定的进程汪嫌运行的实例个数
0 没运行
将以下代码添加在时腔裂钟事件中就伍陵闭可以了
char a[256] = "c:\windows\1.exe"
if (GetProcessCount(a) == 0)
WinExec(a, SW_SHOWNORMAL)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)