发表于:2006-03-13 11:20:00
3楼
谢谢提示楼上的同志,我已经实现了该功能:以下为VBA代码
实现策略:
通过IFIX的调度,增加一定时调度,在调度中调用查询进程状况,没有该WSQLODC.EXE进程,则运行.
通过测试,可以实现SQL数据源的动态刷新,更新了ODBC数据源,也可以不用重起IFIX了
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String * 1024
End Type
Const TH32CS_SNAPHEAPLIST = &H1
Const TH32CS_SNAPPROCESS = &H2
Const TH32CS_SNAPTHREAD = &H4
Const TH32CS_SNAPMODULE = &H8
Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE)
Const TH32CS_INHERIT = &H80000000
Dim My As PROCESSENTRY32
Dim L As Long
Dim L1 As Long
Dim Flag As Boolean
Dim mName As String
Dim I As Integer
Sub QUERY()
L = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
If L Then
My.dwSize = 1060
If (Process32First(L, My)) Then '遍历第一个进程
Do
I = InStr(1, My.szExeFile, Chr(0))
mName = UCase(Left(My.szExeFile, I - 1)) '大写程序名
If mName = "WSQLODC.EXE" Then '发现进程,则退出判断
Flag = True
Exit Sub
Else
Flag = False
End If
Loop Until (Process32Next(L, My) < 1) '遍历所有进程知道返回值为False
End If
L1 = CloseHandle(L)
End If
If Flag = False Then '没有发现进程,则运行WSQLODC
Shell "C:\DYNAMICS\WSQLODC.EXE /CA45 /CL1000", vbHide
End If
End Sub