Tag Archives: Excel VBA

Making Invisible Internet Explorer Instances Visible

While investigating behavior I had previously documented in which SuperAntiSpyware spawns hidden iexplore.exe processes. Rather than terminating them blindly, I wanted a way to make every existing Internet Explorer instance visible so I could see exactly what was going on.

Internet Explorer is not just a browser. It is also a COM automation server. This allows applications, scripts, and services to create Internet Explorer instances in the background for tasks such as report generation, authentication flows, or legacy system integrations. When those instances are created with their visibility turned off, or are never explicitly shown, they can remain running long after their original purpose has passed.

Task Manager will show the process, but it offers no insight into why it exists or what it is doing. Ending the process may remove the symptom, but it does not explain the behavior and can potentially disrupt the software that created it.

What I wanted was simple.

If Internet Explorer is running, I wanted to see it, see what it was up to.
 
Continue reading

How to Terminate a Windows Process Using VBA (Shell, WMI, and API Methods)

Following my previous post on working with Windows processes, specifically:

this article explores different techniques for terminating a Windows process using VBA.
 
Continue reading

Using VBA to List Active Processes

Because of some recent work I’ve been doing trying to embed applications within an Access form (so far I’ve managed to embed Brave, Edge, PowerShell ISE, Excel, Word, …) I’ve been working with listing the active computer processes. So I thought I’d share a few procedures I’ve developed to aid me with that task.

I tried a couple different approaches to get the process listing.

Initially, I was using the cmd:

tasklist /fo csv /nh

and although it did work, it was slow and created unnecessary lag in my process (no pun intended). Eventually I turned to my tried, tested and true friend WMI!
 
Continue reading

Read Data From An Access Database

As with most things in life, there are many ways to tackle such a need as reading data from an Access database from other applications (Excel, Word, …), but today I thought I’d demonstrate just how easy it is to do with some simple VBA.

Continue reading

VBA – Is AlphaNumeric

One last post regarding validating inputs using Regular Expressions, specifically ensuring a string is alphanumeric.

Like all the previous posts, it is merely a question of using the appropriate Pattern as shown below!
Continue reading

VBA – Is Numeric

Another posts about the power of using Regular Expressions, and thought provide a simple function to validate if an entry is entirely numeric (no alphabetic or special characters), just 0 through 9.

Like for alphabetical validation, typically you’ll see code that will loop through a string character by character and validate the value against the ascii value, but with RegEx, it can be done with a simple pattern as shown below.
Continue reading

VBA – Is Alpha

Continuing on my recent posts regarding using Regular Expressions, I thought I should provide a simple function to validate if an entry is entirely alpha (no numbers or special characters), just a to z.

Typically you’ll see code that will loop through a string character by character and validate the value against the ascii value, but with RegEx, it can be done with a simple pattern as shown below.
Continue reading

VBA – Is Uppercase?

Once again, helping in a forum, a user needed a way to determine if the entry was entirely in Uppercase or not. In this particular case, the user absolutely wanted to use a Regular Expression for the validation. So I thought I’d share how it can be done in the hopes it may help others with a similar need.

Continue reading

VBA-WMI-Determine If a Process or Program Is Running Or Not

Here’s a simple technique (pulling it out of archive to help answer a thread in a discussion forum) to verify whether or not a program (actually a process) is currently running on a computer, local or remote (if the permissions have been establish to validate such information remotely), using a simple WMI query.

'---------------------------------------------------------------------------------------
' Procedure : WMI_IsProcessRunning
' Author    : Daniel Pineault, CARDA Consultants Inc.
' Website   : http://www.cardaconsultants.com
' Purpose   : Determine if a process or Program is running or not
'               Returns: True/False
' Copyright : The following is release as Attribution-ShareAlike 4.0 International
'             (CC BY-SA 4.0) - https://creativecommons.org/licenses/by-sa/4.0/
' Req'd Refs: Uses Late Binding, so none required
'
' Input Variables:
' ~~~~~~~~~~~~~~~~
' sExeName  : Name of the process to look for
' sHost     : Host computer to query, omit for the local PC
'
' Usage:
' ~~~~~~
' WMI_IsProcessRunning("firefox.exe")
' WMI_IsProcessRunning("outlook.exe")
' WMI_IsProcessRunning("msaccess.exe", "HomePC01")
' WMI_IsProcessRunning("msaccess.exe", "192.168.100.12")
'
' Revision History:
' Rev       Date(yyyy/mm/dd)        Description
' **************************************************************************************
' 1         2010-Feb-03             Initial Release
' 2         2020-08-21              Renamed the Function
'                                   Updated Proc Header
'                                   Code updated
'                                   Updated Error Handler
'---------------------------------------------------------------------------------------
Public Function WMI_IsProcessRunning(sProcessName As String, Optional sHost As String = ".") As Boolean
    On Error GoTo Error_Handler
    Dim oWMI                  As Object    'WMI object to query about the PC's OS
    Dim sWMIQuery             As String    'WMI Query
    Dim oCols                 As Object
    Dim oCol                  As Object

    Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & sHost & "\root\cimv2")
    sWMIQuery = "SELECT * FROM Win32_Process WHERE Name = '" & sProcessName & "'"
    Set oCols = oWMI.ExecQuery(sWMIQuery)
    If oCols.Count <> 0 Then WMI_IsProcessRunning = True

Error_Handler_Exit:
    On Error Resume Next
    Set oCols = Nothing
    Set oWMI = Nothing
    Exit Function

Error_Handler:
    MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
           "Error Number: " & Err.Number & vbCrLf & _
           "Error Source: WMI_IsProcessRunning" & vbCrLf & _
           "Error Description: " & Err.Description & _
           Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
           , vbOKOnly + vbCritical, "An Error has Occurred!"
    Resume Error_Handler_Exit
End Function

There are some other great resources on the subject of WMI to further develop such code. I good starting point is MSDN, see: WMI Tasks: Processes