查看: 39  |  回复: 0
  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


您需要登录后才可以回帖 登录 | 立即注册
【本版规则】请勿发表违反国家法律的内容,否则会被冻结账号和删贴。
用户名: 立即注册
密码:
2020-2025 MaNongKu.com