|
-
Jun 26th, 2000, 04:35 AM
#1
Thread Starter
Hyperactive Member
I need to force a program to kill itself
I already have the way to get the handle of it, but from some reason the program will resist the
SC_CLOSE command.
is there any other way to kill it appart from rebooting the machine ???
In the beginning the universe was created. This has made a lot of people very angry and is generally regarded as a bad idea.
- Douglas Adams
The Hitchhiker's Guide to the Galaxy
-
Jun 26th, 2000, 06:43 PM
#2
transcendental analytic
You could send a WM_CLOSE message with postmessage api
Code:
PostMessage appwnd&, WM_CLOSE, 0, 0
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jun 26th, 2000, 10:28 PM
#3
I believe the CloseHandle API should work as well.
-
Jun 26th, 2000, 10:35 PM
#4
Thread Starter
Hyperactive Member
I will try both (I am in the proccess of trying the first..
Someone told me that nothing would work because this game is using DirectX drivers, so It will not "listen" to the commands from windows, is that true ???
if it is true, than I need to find a way to crash the application, how do you send ALL the windows commands in a loop (open,close,minimize,maximize ...) this might crash it eventually ? what is the range of numbers I should put in the loop (I don't want to crash the whole machine).
In the beginning the universe was created. This has made a lot of people very angry and is generally regarded as a bad idea.
- Douglas Adams
The Hitchhiker's Guide to the Galaxy
-
Jun 26th, 2000, 11:06 PM
#5
Thread Starter
Hyperactive Member
NOTHING absulutly NOTHING
this program really takes over ...
I will probably need to crash the whole machine before getting rid of it.
Any suggestions from anybody ??
In the beginning the universe was created. This has made a lot of people very angry and is generally regarded as a bad idea.
- Douglas Adams
The Hitchhiker's Guide to the Galaxy
-
Jun 27th, 2000, 02:45 AM
#6
transcendental analytic
You could try these, i haven't used them but they might be usefull
Code:
Declare Function TerminateProcess Lib "kernel32" Alias "TerminateProcess" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Declare Function GetWindowThreadProcessId Lib "user32" Alias "GetWindowThreadProcessId" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
'I have never used these but
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jun 27th, 2000, 02:58 AM
#7
Thread Starter
Hyperactive Member
Thanks, I will try
The only way I could kill it was with causing a blue screen, and than again, the program would still continue (all screwed up , but still running) it is like a giant that can't be killed..
The whole machine was totally screwed up, but this was going on ...
I just wrote a C++ program that would REALLY crash the machine (allocating endless memorry, never use it, and than allocating more ... 100000000 times)
so I will try this as well...
Again, I will try your code though.
thanks
In the beginning the universe was created. This has made a lot of people very angry and is generally regarded as a bad idea.
- Douglas Adams
The Hitchhiker's Guide to the Galaxy
-
Jun 29th, 2000, 12:33 AM
#8
New Member
Cool
" How can I close an application?"
You can use the FindWindow and PostMessage API functions to find a window and then close it. This example show how you can close down a Window with a caption of "Calculator".
Dim winHwnd As Long
Dim RetVal As Long
winHwnd = FindWindow(vbNullString, "Calculator")
Debug.Print winHwnd
If winHwnd <> 0 Then
RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&)
If RetVal = 0 Then
MsgBox "Error posting message."
End If
Else
MsgBox "The Calculator is not open."
End If
Before this,you have to declare the API functions in a module in your project.
Declarations : ( PostMessage and FindWindow )
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Good Luck Asabi.
Regards,Supera.
-
Jun 29th, 2000, 12:44 AM
#9
Thread Starter
Hyperactive Member
Well, the thing is that this program is using directX so it won't close with this command (I have tried), infact, I sent a command to shut off windows (the operating system), and this program was still running !, just when I quit this program THAN the whole thing would reboot.
I found my way ...
I found an EXE file that would crash the whole machine ..., that's the only way I could find.
Thank you
In the beginning the universe was created. This has made a lot of people very angry and is generally regarded as a bad idea.
- Douglas Adams
The Hitchhiker's Guide to the Galaxy
-
Jul 1st, 2000, 11:18 PM
#10
New Member
Can someone help with this code!
I need to know how to close a program that is runing?
How do I do this?
If possible can someone send me a demo of how the code works?
My E-Mail: [email protected]
any information is helpfull to me.... Thanks
~Joe
-
Jul 2nd, 2000, 10:39 AM
#11
You can close an Already running App like this. Put the following code into a Module.
Code:
Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const WM_CLOSE = &H10
Now put this Code into a CommandButton
Code:
Private Sub Command1_Click()
' Get the Handle of Calculator
chWnd = FindWindow(CLng(0), "Calculator")
' Send a Message to close it
SendMessage chWnd, WM_CLOSE, CLng(0), CLng(0)
End Sub
This code will Close Calculator. Before you run the code, make sure that you have Calculator running. If you want, you can modify the code to suit yourself by replacing the "Calculator" with another Application's Title.
-
Jul 5th, 2000, 06:33 PM
#12
I personally like this way:
Code:
Const MAX_PATH& = 260
Declare Function TerminateProcess Lib "kernel32" (ByVal ApphProcess As Long, ByVal uExitCode As Long) As Long
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal blnheritHandle As Long, ByVal dwAppProcessId As Long) As Long
Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, lProcessID As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szexeFile As String * MAX_PATH
End Type
Public Function KillApp(myName As String) As Boolean
Const PROCESS_ALL_ACCESS = 0
Dim uProcess As PROCESSENTRY32
Dim rProcessFound As Long
Dim hSnapshot As Long
Dim szExename As String
Dim exitCode As Long
Dim myProcess As Long
Dim AppKill As Boolean
Dim appCount As Integer
Dim i As Integer
On Local Error Goto Finish
appCount = 0
Const TH32CS_SNAPPROCESS As Long = 2&
uProcess.dwSize = Len(uProcess)
hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
rProcessFound = ProcessFirst(hSnapshot, uProcess)
Do While rProcessFound
i = InStr(1, uProcess.szexeFile, Chr(0))
szExename = LCase$(Left$(uProcess.szexeFile, i - 1))
If Right$(szExename, Len(myName)) = LCase$(myName) Then
KillApp = True
appCount = appCount + 1
myProcess = OpenProcess(PROCESS_ALL_ACCESS, False, uProcess.th32ProcessID)
AppKill = TerminateProcess(myProcess, exitCode)
Call CloseHandle(myProcess)
End If
rProcessFound = ProcessNext(hSnapshot, uProcess)
Loop
Call CloseHandle(hSnapshot)
Finish:
End Function
-
Jul 6th, 2000, 02:17 PM
#13
Thread Starter
Hyperactive Member
what is myName (in the call for the function)?
Is it the window caption ?
In the beginning the universe was created. This has made a lot of people very angry and is generally regarded as a bad idea.
- Douglas Adams
The Hitchhiker's Guide to the Galaxy
-
Jul 6th, 2000, 05:13 PM
#14
It is the EXE ("C:\myapp\app.exe").
If you would like an project sample instead. Here is the link: http://www.planet-source-code.com/vb...txtCodeId=4377
[Edited by Matthew Gates on 07-06-2000 at 06:16 PM]
-
Jul 8th, 2000, 11:17 AM
#15
Fanatic Member
DestroyWindow
You might try to use the DestroyWindow(TheThingYouWantToDestroy.hwnd)
API?
That closes the window but doesn't end the prog.
But what the hell do I know?
-
Jul 8th, 2000, 11:49 AM
#16
Thread Starter
Hyperactive Member
Well, I have already used Matthew Gates method, and it did work (everything else never worked) this program does not really work in a window, and it is using the direct X libarary so it doesn't really listens to the windows commands (even killing explorer just hanged the machine, but not this program.
Now it works though (with killing the proccess).
Thank you :-)
In the beginning the universe was created. This has made a lot of people very angry and is generally regarded as a bad idea.
- Douglas Adams
The Hitchhiker's Guide to the Galaxy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|