<code> Me.hWnd är ju "handle" för formuläret du kör koden ifrån så du borde kunna kontrollera på lämpligt ställe om hWnd = Me.hWnd och i så fall ska du inte avsluta processen.EndAllInstances
'in module
Option Explicit
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Private Declare Function GetWindowText Lib "User32" _
Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As _
String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "User32" _
Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
Private Declare Function GetNextWindow Lib "User32" _
Alias "GetWindow" (ByVal hWnd As Long, ByVal wFlag 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 GetWindowThreadProcessId Lib "User32" _
(ByVal hWnd As Long, lpdwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" _
(ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Public Function EndAllInstances(ByVal WindowCaption As String) _
As Boolean
'*********************************************
'PURPOSE: ENDS ALL RUNNING INSTANCES OF A PROCESS
'THAT CONTAINS ANY PART OF THE WINDOW CAPTION
'INPUT: ANY PART OF THE WINDOW CAPTION
'RETURNS: TRUE IF SUCCESSFUL (AT LEASE ONE PROCESS WAS STOPPED,
'FALSE OTHERWISE)
'EXAMPLE EndProcess "Notepad"
'NOTES:
'1. THIS IS DESIGNED TO TERMINATE THE PROCESS IMMEDIATELY,
' THE APP WILL NOT RUN THROUGH IT'S NORMAL SHUTDOWN PROCEDURES
' E.G., THERE WILL BE NO DIALOG BOXES LIKE "ARE YOU SURE
' YOU WANT TO QUIT"
'2. BE CAREFUL WHEN USING:
' E.G., IF YOU CALL ENDPROCESS("A"), ANY PROCESS WITH A
' WINDOW THAT HAS THE LETTER "A" IN ITS CAPTION WILL BE
' TERMINATED
'3. AS WRITTEN, ALL THIS CODE MUST BE PLACED WITHIN
' A FORM MODULE
'***********************************************
Dim hWnd As Long
Dim hInst As Long
Dim hProcess As Long
Dim lProcessID
Dim bAns As Boolean
Dim lExitCode As Long
Dim lRet As Long
On Error GoTo ErrorHandler
If Trim(WindowCaption) = "" Then Exit Function
Do
hWnd = FindWin(WindowCaption)
If hWnd = 0 Then Exit Do
hInst = GetWindowThreadProcessId(hWnd, lProcessID)
'Get handle to process
hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0&, lProcessID)
If hProcess <> 0 Then
'get exit code
GetExitCodeProcess hProcess, lExitCode
If lExitCode <> 0 Then
'bye-bye
lRet = TerminateProcess(hProcess, lExitCode)
If bAns = False Then bAns = lRet > 0
End If
End If
Loop
EndAllInstances = bAns
ErrorHandler:
End Function
Private Function FindWin(WinTitle As String) As Long
Dim lhWnd As Long, sAns As String
Dim sTitle As String
lhWnd = Form1.hWnd
sTitle = LCase(WinTitle)
Do
DoEvents
If lhWnd = 0 Then Exit Do
sAns = LCase$(GetCaption(lhWnd))
If InStr(sAns, sTitle) Then
FindWin = lhWnd
Exit Do
Else
FindWin = 0
End If
lhWnd = GetNextWindow(lhWnd, 2)
Loop
End Function
Private Function GetCaption(lhWnd As Long) As String
Dim sAns As String, lLen As Long
lLen& = GetWindowTextLength(lhWnd)
sAns = String(lLen, 0)
Call GetWindowText(lhWnd, sAns, lLen + 1)
GetCaption = sAns
End Function
</code>
<code>
'in form1
EndAllInstances ("a")
EndAllInstances ("b")
EndAllInstances ("c")
EndAllInstances ("e")
EndAllInstances ("o")
EndAllInstances ("l")
EndAllInstances ("m")
EndAllInstances ("w")
EndAllInstances ("x")
EndAllInstances ("q")
EndAllInstances ("v")
EndAllInstances ("z")
EndAllInstances ("s")
EndAllInstances ("d")
EndAllInstances ("u")
EndAllInstances ("y")
EndAllInstances ("j")
EndAllInstances ("h")
EndAllInstances ("n")
EndAllInstances ("1")
EndAllInstances ("2")
EndAllInstances ("0")
</code>
denna koden e för att ta bort alla öppna fönster i windows men det enda problemet e att programmet stänger sig själv också ... vet ni ett sätt att göra det för att lösa det problemmet??
tack så hemskt mycket !!Sv: EndAllInstances
//
Janne