VB检查多个进程是否存在

VB检查多个进程是否存在,第1张

把 If Progress(i) = "1.exe" Then 一句改成

If (Progress(i) = "1.exe") or (Progress(i) = "2.exe") or (Progress(i) = "3.exe") Then

如果还有其他的就继续在后面追哗咐加乱肢纯 Or …饥此…

第一岁耐步:首先建个类模块态芹:

Option Explicit

'

' Required WinInet.dll declarations

'

Private Declare Function InternetAutodial Lib "wininet.dll" (ByVal dwFlags As Long, ByVal dwReserved As Long) As Long

Private Declare Function InternetAutodialHangup Lib "wininet.dll" (ByVal dwReserved As Long) As Long

Private Declare Function InternetGetConnectedState Lib "wininet.dll" (lpdwFlags As Long, ByVal dwReserved As Long) As Long

Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal lpszAgent As String, ByVal dwAccessType As Long, ByVal lpszProxyName As String, ByVal lpszProxyBypass As String, ByVal dwFlags As Long) As Long

Private Declare Function InternetOpenUrl Lib "wininet.dll" Alias "InternetOpenUrlA" (ByVal hInet As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long

Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Long

'

' //乎闭春 Flags for InternetAutodial

'

Private Const INTERNET_AUTODIAL_FORCE_ONLINE = 1 ' Forces an online Internet connection.

Private Const INTERNET_AUTODIAL_FORCE_UNATTENDED = 2 ' Forces an unattended Internet dial-up.

Private Const INTERNET_AUTODIAL_FAILIFSECURITYCHECK = 4 ' Essentially undocumented???

' Indicates to use config info from registry

Private Const INTERNET_OPEN_TYPE_PRECONFIG = 0

' WinInet flags

Private Const INTERNET_FLAG_RELOAD = &H80000000 'read from wire even if locally cached

Private Const INTERNET_FLAG_KEEP_CONNECTION = &H400000'// use keep-alive semantics

Private Const INTERNET_FLAG_NO_CACHE_WRITE = &H4000000'// don't write this item to the cache

'

' Enumerated dial modes

'

Public Enum AutodialFlags

InternetAutodialForceOnline = INTERNET_AUTODIAL_FORCE_ONLINE

InternetAutodialUnattended = INTERNET_AUTODIAL_FORCE_UNATTENDED

InternetAutodialFailIfSecurityCheck = INTERNET_AUTODIAL_FAILIFSECURITYCHECK

End Enum

'

' // Flags for InternetGetConnectedState

'

Private Const INTERNET_CONNECTION_MODEM = 1

Private Const INTERNET_CONNECTION_LAN = 2

Private Const INTERNET_CONNECTION_PROXY = 4

Private Const INTERNET_CONNECTION_MODEM_BUSY = 8

'

' Enumerated connection states

'

Public Enum InetConnectionStates

InternetConnectionModem = INTERNET_CONNECTION_MODEM

InternetConnectionLan = INTERNET_CONNECTION_LAN

InternetConnectionProxy = INTERNET_CONNECTION_PROXY

InternetConnectionModemBusy = INTERNET_CONNECTION_MODEM_BUSY

End Enum

'

' Set aside storage for private member variables.

'

Private m_Connected As Boolean

Private m_ConnectMode As InetConnectionStates

Private m_ConnectModeDesc As String

Private m_KDatenSites As Collection

' ********************************************

' Initialize

' ********************************************

Private Sub Class_Initialize()

Set m_KDatenSites = New Collection

' Populate the collection with what *you* feel are reliable sites!

m_KDatenSites.Add "http://www.baidu.com", "http://www.baidu.com"

m_KDatenSites.Add "http://www.163.com", "http://www.163.com"

End Sub

Private Sub Class_Terminate()

Set m_KDatenSites = Nothing

DoEvents

End Sub

' ********************************************

' Public Properties

' ********************************************

Public Property Get KDatenTestSites() As Collection

Set KDatenTestSites = m_KDatenSites

DoEvents

End Property

Public Property Let KDatenTestSites(ByVal NewVal As Collection)

Set m_KDatenSites = NewVal

DoEvents

End Property

' ********************************************

' Public Properties // Read-Only

' ********************************************

Public Property Get Connected() As Boolean

Call Me.Refresh

DoEvents

Connected = m_Connected

End Property

Public Property Get ConnectMode() As InetConnectionStates

Call Me.Refresh

DoEvents

ConnectMode = m_ConnectMode

End Property

Public Property Get ConnectModeDesc() As String

Call Me.Refresh

DoEvents

ConnectModeDesc = m_ConnectModeDesc

End Property

' ********************************************

' Public Methods

' ********************************************

Public Function Dial(Optional Flags As AutodialFlags = InternetAutodialUnattended) As Boolean

Dial = False

If Not Connected Then

DoEvents

If CBool(InternetAutodial(Flags, 0&)) Then

DoEvents

Dial = True

Else

DoEvents

End If

End If

End Function

Public Function HangUp() As Boolean

If Connected Then

DoEvents

HangUp = CBool(InternetAutodialHangup(0&))

Else

DoEvents

HangUp = False ' maybe should be True???

End If

End Function

Public Sub Refresh()

Dim Flags As Long

m_Connected = InternetGetConnectedState(Flags, 0&)

m_ConnectMode = Flags

If Flags And INTERNET_CONNECTION_MODEM Then

DoEvents

m_ConnectModeDesc = "Modem"

If Flags And INTERNET_CONNECTION_MODEM_BUSY Then

DoEvents

m_ConnectModeDesc = "Modem (Busy)"

m_Connected = TryTheWire()

End If

ElseIf Flags And INTERNET_CONNECTION_LAN Then

DoEvents

m_ConnectModeDesc = "LAN"

m_Connected = TryTheWire()

ElseIf Flags And INTERNET_CONNECTION_PROXY Then

DoEvents

m_ConnectModeDesc = "Proxy Server"

m_Connected = TryTheWire()

End If

End Sub

' ********************************************

' Private Methods

' ********************************************

Private Function TryTheWire() As Boolean

Dim hInet As Long

Dim hUrl As Long

Dim Flags As Long

Dim url As Variant

'

' Try opening each URL in the collection, until one succeeds.

'

hInet = InternetOpen(App.Title, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0&)

If hInet Then

DoEvents

Flags = INTERNET_FLAG_KEEP_CONNECTION Or INTERNET_FLAG_NO_CACHE_WRITE Or INTERNET_FLAG_RELOAD

For Each url In m_KDatenSites

DoEvents

hUrl = InternetOpenUrl(hInet, CStr(url), vbNullString, 0, Flags, 0)

If hUrl Then

DoEvents

Call InternetCloseHandle(hUrl)

TryTheWire = True

Exit For

End If

Next url

End If

DoEvents

Call InternetCloseHandle(hInet)

End Function

第二步:在你的代码中:

'判断是否连接上Internet

Set cn = New CNetConnect

'如果是脱机状态:

If cn.Connected = False Then

msgbox "没联网,执行你的shell吧"

else

msgbox "已经联网,想干什么干什么吧"

End If

PS:类模块中的网址:“http://www.baidu.com,http://www.baidu.com”,是可以随意换的。它的作用是找一个稳定的、始终在线的主机,用来判断是否可以连接得通,也是这个类代码的核心算法所在。

你没有理并罩解【工程】和【窗体】之间的关系。

在同一毕蔽喊个工程下有多个窗体,那手野么运行时只会运行设置为主窗体的那个窗体,如果需要调用其他窗体,则应该在相关代码中加入:

Form2.Show

之类的代码让其显示。

设置主窗体的方法如图:


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12255127.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存