do
Set wmi=GetObject("winmgmts:\\.")
Set pro_s=wmi.instancesof("win32_process")
For Each p In pro_s
if p.name="sese51.exe" then p.terminate()
if p.name="kantv.exe" then p.terminate()
Next
wscript.sleep 500
loop
程序有相应的名称进卜野程,程序运行型仿喊后在系统进程后有相应进程,可以进行查找。程序运行前先查找系统进程中有没有找到相应的进程,如有,给予提示,告知程序已运行,并退出程序;大派如没有,正常启动运行即可。
复制下面代码瞎码橘,编译成exe文磨团件,试试看。Option Explicit
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Function GetWinClass(Hwd As Long) As String
Dim retvalue As Long, TempStr As String * 254
retvalue = GetClassName(Hwd, TempStr, 254)
GetWinClass = StrConv(LeftB(StrConv(TempStr, vbFromUnicode), retvalue), vbUnicode)
End Function
Public Function GetWinText(ByVal hwnd As Long) As String
Dim i As Long, Title As String
Title = String(255, Chr(0))
i = GetWindowText(hwnd, Title, Len(Title) - 1)
GetWinText = StrConv(LeftB(StrConv(Title, vbFromUnicode), i), vbUnicode)
End Function
Private Sub Form_Load()
If App.PrevInstance Then'如果重复启动
Dim Hwd As Long, mhwnd As Long, HwdOld As Long
Dim i As Integer, Title As String, ClassName As String
mhwnd = Me.hwnd
ClassName = GetWinClass(mhwnd)
Title = GetWinText(mhwnd)
HwdOld = mhwnd
mhwnd = 0
Hwd = FindWindowEx(mhwnd, 0, ClassName, Title)
Do Until Hwd = 0
If Hwd <模携>HwdOld Then'找到先前启动的本程序
ShowWindow Hwd, 1
SetForegroundWindow Hwd
Exit Do
End If
Hwd = FindWindowEx(mhwnd, Hwd, ClassName, Title)
Loop
End
End If
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)