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
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