首页 /编程语言和算法/VB6/VBA/ASP
 VB6 检查项目是否正在VB6IDE中运行
2025年2月25日 18:43

新建From1(窗体),新建Command1(按钮CommandButton),代码:

Private Declare Function GetModuleBaseNameA Lib "Psapi.dll" (ByVal hProcess As Long, ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Const PROCESS_NAME_MAX_BYTES As Long = 255

Private Property Get IfUsingVB6IDE() As Boolean
    Dim ProcessHandle As Long
    Dim ProcessName As String
    Dim ProcessNameLen As Long
    Dim NameBuffer As String * PROCESS_NAME_MAX_BYTES
    
    ProcessHandle = GetCurrentProcess()    'Get Current Process pseudo handle
    ProcessNameLen = GetModuleBaseNameA(ProcessHandle, App.hInstance, NameBuffer, PROCESS_NAME_MAX_BYTES)    'Get current Process Base module name (file name)
    ProcessName = Left$(NameBuffer, ProcessNameLen)    'clear remaining unused buffer bytes and get only file name
    If (UCase$(ProcessName) = "VB6.EXE") Then IfUsingVB6IDE = True    'if current process VB6.exe then we are in VB6 IDE, if else we running as separated process
End Property

Private Sub Command1_Click()
    MsgBox IfUsingVB6IDE
End Sub


 
全部回复(0)
首页 | 电脑版 |