0, 0, True, 32, ByVal 0 As Long, vbNullString, StartInfo, Pro_Info’ 否则用被监控进程的全路径文件名来创建被监控进程
WaitForTheProcess Pro_Info.hProcess, sPath
End Sub
Public Function GetProcessHandle As Long(ByVal sPath As String)’获取被监控进程的进程句柄
sPath = LCase(sPath)
hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)’创建一个snapshot对象
pe.dwSize = Len(pe)
bValue = Process32First(hSnapshot, pe)’开始遍历系统进程池
While bValue <> 0
If InStr(LCase(pe.szExeFile), sPath) <> 0 Then’如果找到了,则…
Dim hProcess As Long
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0, pe.th32ProcessID)
GetProcessHandle = hProcess
CloseHandle hSnapshot
Exit Function
End If
bValue = Process32Next(hSnapshot, pe)
Wend
CloseHandle hSnapshot
GetProcessHandle = 0’否则返回0
End Function
Public Function GetOkButton(ByVal hwnd As Long, ByVal lParam As Long) As Long’获取“输入网络密码框”窗口中“确定”按钮的句柄
Dim Length&, ListItem$
Length = GetWindowTextLength(hwnd)
If Length <> 0 Then
ListItem$ = Space$(Length)
Length = GetWindowText(hwnd, ListItem$, Length + 2)
If InStr(ListItem, "确定") <> 0 Then
SendMessage hwnd, BM_CLICK, 0, 0’激活窗口
SendMessage hwnd, BM_CLICK, 0, 0’发送Click消息
GetOkButton = 0’退出EnumChildWindows()函数的枚举循环
Exit Function
End If
End If
GetOkButton = 1’继续EnumChildWindows()函数的枚举循环
End Function
窗口中有几个Label控件:
Label2用来提示当前被监控的进程的,Label4和Label6用来记录次数的。窗口中还有一个菜单,用来向用户提供设置方法的。因为允许操作人员设置,不能隐藏窗口,所以这里隐藏了菜单,在窗口上用鼠标点右键才能看见,而触摸屏上顾客是无法点右键的,这样设置就安全了,具体的菜单项见下面
程序:
作者:安徽省滁州市电信局小型机房 徐原
来自:
计算机世界网
Private Sub Form_Load()
RegisterServiceProcess GetCurrentProcessId, RSP_SIMPLE_SERVICE’注册进程为系统服务进程,这样进程只在系统关机的最后一刻才从系统中卸掉。
Dim FN As String, hReg As Long, tRegKey As String, tSubKey As String, phkResult As Long, lpSubKey As String, EnterResult As Long
Dim TimePassed1 As Long, TimePassed2 As Long
FN = Space(255)
GetModuleFileName App.hInstance, FN, 255’获取当前进程的全路径文件名
FN = Trim(FN)
lpSubKey = "Sysexplor"
tSubKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\RunServices"
RegOpenKey HKEY_LOCAL_MACHINE, tSubKey, phkResult’打开注册表项
RegSetValueEx phkResult, lpSubKey, 0, REG_SZ, FN, Len(FN)’写当前进程的全路径到上面所说的注册表项中,以便下次系统重启说能和系统登陆对话框一同运行
RegCloseKey phkResult’关闭注册表项
AppName = "TiMonitor"
Section = "Reboot"
sKeyFile = "FileName"
sFileName = GetSetting(AppName, Section, sKeyFile, "")’读取注册表中记录的被监控进程的全路径名
aa:If Len(Dir(sFileName, vbDirectory)) < 4 Then
sFileName = "c:\teleinfo\ti.exe"’如果读取不到或系统不存在相应的文件,则取一个默认值。或者给一个提示:
''sFileName = InputBox("找不到程序,请输入包含全路径的
程序名:", "输入", "C:\te