A Better Substitute for GetModuleUsage

A Better Substitute for GetModuleUsage

To synchronously shell an application from a 16-bit VB application, some people write code like this:

 Const HINSTANCE_ERROR% = 32Dim hInstChild As Integer'Shell program, if Shell worked, enter loophInstChild = Shell(strExeName, intCmdShow)If hInstChild >= HINSTANCE_ERROR Then    While GetModuleUsage(hInstChild)        DoEvents    WendEnd If

This code relies on a 16-bit-only API function, GetModuleUsage. Several 32-bit workarounds have been published, but here is the simplest and most reliable solution I’ve seen:

 Declare Function OpenProcess Lib "Kernel32" _    (ByVal dwDesiredAccess As Long, _    ByVal bInheritHandle As Long, _    ByVal dwProcessId As Long) As LongDeclare Function WaitForSingleObject Lib "Kernel32" _    (ByVal hHandle As Long, _    ByVal dwMilliseconds As Long) As LongConst SYNCHRONIZE = &H100000Const INFINITE = &HFFFFFFFFPrivate Function SyncShell(ByVal pathname As String, _    windowstyle As Integer) As BooleanDim ProcessID As LongDim ProcessHandle As Long' In VB4, an error occurs if Shell' fails to start the programOn Error GoTo SyncShell_Error' Shell the program, get its handle, ' and wait for it to terminateProcessID = Shell(pathname, windowstyle)ProcessHandle = OpenProcess(SYNCHRONIZE, True, ProcessID)WaitForSingleObject ProcessHandle, INFINITESyncShell = TrueExit FunctionSyncShell_Error:    On Error GoTo 0    SyncShell = False    Exit FunctionEnd Function
Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved