[AccessD] OT copying worksheets

Jim Lawrence accessd at shaw.ca
Thu Sep 14 00:03:20 CDT 2006


Jim:

I guess that is what can be described as collateral damage. It is effective
not selective.

Jim   

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Hale, Jim
Sent: Wednesday, September 13, 2006 2:23 PM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] OT copying worksheets

The only problem I see is this is an indiscriminate killer. If a user has
Excel open and is using it there will be one unhappy camper when the
contracted hitman gets the wrong instance.
Jim Hale

-----Original Message-----
From: Jim Lawrence [mailto:accessd at shaw.ca]
Sent: Wednesday, September 13, 2006 3:20 PM
To: 'Access Developers discussion and problem solving'
Subject: [AccessD] OT copying worksheets


Hi All:

There is also the absolute 'kill; an application. Used back when Access97
kept failing to die.

Brutally Kill an application

Option Explicit

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA"
 (ByVal lpClassName As String, 
  ByVal lpWindowName As String) As Long

Private Declare Function GetWindowThreadProcessId Lib "user32" 
 (ByVal hwnd As Long, 
  lpdwProcessId As Long) As Long

Private Declare Function GetWindowThreadProcessId Lib "user32" 
 (ByVal hwnd As Long, 
  lpdwProcessId As Long) As Long

Private Declare Function OpenProcess Lib "kernel32" 
 (ByVal dwDesiredAccess As Long, 
  ByVal bInheritHandle As Long, 
  ByVal dwProcessId As Long) As Long

Private Declare Function CloseHandle Lib "kernel32" 
 (ByVal hObject As Long) As Long 

Sub Kill ExcelApplication()

 Dim lHwnd As Long
 Dim lPid As Long, 
 Dim lReturn As Long, 
 Dim lhwndProcess As Long
 Dim lpClassName As String
    
 Const PROCESS_ALL_ACCESS = &H1F0FFF
 
 
 ' check to see if application alive and running
 ' Believe that XLMain is the appropriate class 
 ' but could be wrong.. please check. 
 lpClassName = "XLMain"

 lHwnd = FindWindow(lpClassName, vbNullString)

 If lHwnd > 0 Then
    'Get the PID (process ID) from the application handle
    lReturn = GetWindowThreadProcessId(lHwnd, lPid)
    
    'Terminate the application
    lhwndProcess = OpenProcess(PROCESS_ALL_ACCESS, 0&, lPid)
    if (TerminateProcess(lhwndProcess, 0&) <> 0) = True then
	MsgBox "Excel has been sucessfully terminated" 
    Else
	MsgBox "Excel has not been sucessfully terminated" 
    End if

    lReturn = CloseHandle(lhwndProcess) 
 Else
	MsgBox "Excel is not running or Class name is wrong"	  
 End if
End Sub

Jim
 


***********************************************************************
The information transmitted is intended solely for the individual or
entity to which it is addressed and may contain confidential and/or
privileged material. Any review, retransmission, dissemination or
other use of or taking action in reliance upon this information by
persons or entities other than the intended recipient is prohibited.
If you have received this email in error please contact the sender and
delete the material from any computer. As a recipient of this email,
you are responsible for screening its contents and the contents of any
attachments for the presence of viruses. No liability is accepted for
any damages caused by any virus transmitted by this email.
-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list