判断程序处于运行环境还是调试环境

VB 中新建工程,添加一个按钮。

使用的时候,在 IDE 环境下 F5 运行和编译后运行就可以看到效果。

Option Explicit

?

Private Declare Function GetModuleFileName Lib "kernel32" Alias _

??????? "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As _

??????? String, ByVal nSize As Long) As Long

?

Function IsRunUnderVB6() As Boolean

? Dim S As String

? Dim Length As Long

? Length = 256

? S = String(Length, 0)

? Call GetModuleFileName(0, S, Length)

? S = Left(S, InStr(S, Chr(0)) - 1)

? IsRunUnderVB6 = UCase(Right(S, 7)) = "VB6.EXE"

End Function

?

Private Sub Command1_Click()

If IsRunUnderVB6 Then

MsgBox " 调试 "

Else

MsgBox " 运行 "

End If

End Sub

?

看一看,比较简单

Published At
Categories with Web编程
Tagged with
comments powered by Disqus