PDA

View Full Version : [SOLVED:] Intercept an splwow64.exe error



Dave
02-22-2022, 04:59 PM
I have a re-occurring XL program crash which I have determined is caused by the splwow64.exe process. I know the splwow64.exe is supposed to allow 32bit installs to print on 64 bit operating systems. The error has nothing to do with printing and occurs almost predictably on a regular basis during program operation. I messed with setting different default printers to no avail and my splwow64.exe is not corrupted. I realize that likely the only for sure way to fix this error is to install 64 bit XL but this is not going to happen. Anyways, here's a link to a previous discussion...[SOLVED] Excel and splwow64.exe issues (vbaexpress.com) (http://www.vbaexpress.com/forum/showthread.php?64991-Excel-and-splwow64-exe-issues&highlight=splwow64)
I thought that perhaps I could intercept the splwow64.exe operation by setting a global boolean variable and then using a workbook before print event to terminate the process if it occurred unrelated to printing (ie. setting the variable to true if indeed I wanted the application to print). So, I have this workbook code...

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If Not PrintProcessFlag Then
Call TerminateProcess
End If
End Sub
With the following code adapted from Marcster's kb contribution...

Sub TerminateProcess()
Dim strTerminateThis As String
Dim objWMIcimv2 As Object
Dim objList As Object, ObjProcess As Object

strTerminateThis = "splwow64.exe"
Set objWMIcimv2 = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set objList = objWMIcimv2.ExecQuery _
("select * from win32_process where name='" & strTerminateThis & "'")

If objList.Count = 0 Then
Set objList = Nothing
Set objWMIcimv2 = Nothing
Exit Sub
Else
For Each ObjProcess In objList
ObjProcess.Terminate
'MsgBox "DEAD"
Exit For
Next ObjProcess
End If

Set ObjProcess = Nothing
Set objList = Nothing
Set objWMIcimv2 = Nothing
End Sub
As you may guess, this didn't work. The TerminateProcess sub does work. Any thoughts on how to capture when XL runs the splwow64.exe and/or how to fix this very aggravating error? Dave

p45cal
02-23-2022, 11:08 AM
I'm wondering, at first glance, whether the likes of this, just might do what you need?:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
If Not PrintProcessFlag Then Cancel = True
End Sub

Dave
02-23-2022, 04:53 PM
Thanks p45cal for your assistance and code. I will give it a try but I'm not sure that I'm even barking up the right tree with the use of the before print event. The splwow64.exe doesn't run all the time XL is running and I'm not sure what triggers it to run when there's no printing going on (ie. I'm not sure that there's going to be any before print event). Anyways, it seems like a reasonable solution is at the following link. It discusses making a bat file and a vbs file to kill the process on a scheduled interval. But it also suggests that a Windows error reporting 1001 (which is the correct error number) could be used as an event to fire the code. Unfortunately, I don't understand how to code for this. It seems that if I could intercept this event, then I could run the above terminateprocess code to get rid of this aggravation. Here's the link... Applications hang until SPLWOW64 process is killed - Microsoft Community (https://answers.microsoft.com/en-us/windows/forum/all/applications-hang-until-splwow64-process-is-killed/a6acb5f7-22ec-43ec-b2b4-30bad7cebc9e)
This seems to be the relevant code that I really don't understand how to implement...

On an event; On event - Log: Application, Source: Windows Error Reporting, Event ID: 1001
Start a program; "C:\KillWOW.vbs"
I'll give your code a trial. Again, thanks for any assistance. Dave

Dave
02-24-2022, 04:07 PM
An update... thanks p45cal for the suggestion but the result was the same... XL was disabled and was waiting for the splwow64. On this occasion however, manually disabling the splwow64 did nothing to re-enable XL. So, apparently disabling the splwow64 after the fact, that had previously been successful, is not the solution that I had hoped for. On the upside, I found out what was triggering the splwow64 to run. Part of a routine changed some fonts in a range and this was causing the splwow64 to run. It's apparently supposed to shut itself off in 2 mins after printing (if printing was going on) but seems to remain on permanently after being invoked even though no further font manipulation was occurring. So, I ran the terminateprocess sub after that font change routine and ended the splwow64. Drum roll... It remained off until XL froze but this time the task manger indicated that XL was running normally...Doh!!! I'm going to have to do some more messing around to find out what's really going on. I'll mark this witch hunt solved. Thanks again for your help. Dave