判断程式是独立执行还是在VB环境下执行

来源:王国荣

此时可呼叫 GetModuleFileName API 函数判断执行档名称是否为 VB5,如果是 VB5
, 则GetModuleFileName 最右边的 7 个字元将等於 "VB5.EXE",

Private Declare Function GetModuleFileName Lib "kernel32" Alias _
        "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As _
        String, ByVal nSize As Long) As Long

Function IsRunUnderVB5() As Boolean
 Dim S As String, Length
 Length = 256
 S = String(Length, 0)
 Call GetModuleFileName(0, S, Length)
 S = Left(S, InStr(S, Chr(0)) - 1)
 IsRunUnderVB5 = UCase(Right(S, 7)) = "VB5.EXE"
End Function