|
-
Aug 8th, 2002, 02:44 AM
#1
Thread Starter
Hyperactive Member
Remove something from memory?
After I quit a program (Diablo2), it doesn't completely remove it from memory, which causes my computer to not shutdown properly. When I run Spy++, I can see that it's still in memory, but when I press ctrl+alt+del, it's not in the task list. Question is: How can I wipe it from memory?
[vbcode]
' comment
Rem remark
[/vbcode]
-
Aug 8th, 2002, 07:53 AM
#2
Software Eng.
-
Aug 12th, 2002, 11:08 PM
#3
Thread Starter
Hyperactive Member
Well, I tried process viewer, and that didn't kill it completely either. I'd click the process (Game.exe) and it'd ask if I wanted to kill it and I'd click yes... it refreshed with the process still running. Any other ideas?
Last edited by Oafo; Aug 14th, 2002 at 06:44 PM.
[vbcode]
' comment
Rem remark
[/vbcode]
-
Aug 14th, 2002, 06:44 PM
#4
Thread Starter
Hyperactive Member
Cmon Megatron, you're supposed to be the good one here
[vbcode]
' comment
Rem remark
[/vbcode]
-
Aug 14th, 2002, 06:59 PM
#5
Software Eng.
Sorry, my computer crashed a couple days ago, and I had to re-install everything 
Have you tried using the TerminateProcess API?
I'll see if I can find an example for you.
-
Aug 14th, 2002, 07:02 PM
#6
Software Eng.
OK, here's an example.
VB Code:
Private Declare Function ProcessFirst Lib "kernel32" _
Alias "Process32First" (ByVal hSnapshot As Long, uProcess _
As PROCESSENTRY32) As Long
Private Declare Function ProcessNext Lib "kernel32" _
Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As _
PROCESSENTRY32) As Long
Private Declare Function CreateToolhelpSnapshot Lib "kernel32" _
Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, _
lProcessID As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject _
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 TerminateProcess Lib "kernel32" _
(ByVal hProcess As Long, ByVal uExitCode 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
'Usage
Call KillApp("C:\Program.exe")
-
Aug 15th, 2002, 06:20 PM
#7
Frenzied Member
If you set every object variable to Nothing when it is no longer needed..(like database connections, recordsets, or any object)
If you unload each form when your application is closed.. Then
The program will be clean sweaped automatically from memory. right?
-
Aug 17th, 2002, 08:30 PM
#8
Software Eng.
But he's dealing with an external process here
-
Aug 17th, 2002, 09:37 PM
#9
Hyperactive Member
Try rewriting it's entire process memory first. Make it all zero, the either it will cease functioning and exit, generate a huge error and exit, or be in an exposed position for you to terminate it.
-
Aug 17th, 2002, 11:30 PM
#10
PowerPoster
Originally posted by snakeeyes1000
Try rewriting it's entire process memory first. Make it all zero, the either it will cease functioning and exit, generate a huge error and exit, or be in an exposed position for you to terminate it.
I think this mehtod will shut down your application rather than the target application by causing an illegal operation error. I don't think you an write to another process's memory.
-
Aug 18th, 2002, 08:18 AM
#11
Hyperactive Member
yes you can. Open the process with the WriteProcessMemory flag and use the WriteProcessMemory API. At least I think... been a while since I used it.
-
Aug 18th, 2002, 12:15 PM
#12
Thread Starter
Hyperactive Member
I think that would require you having to go through each and every memory address and set it to zero, which could take a while depending on what program it is. Afterall, it IS VB ya know
[vbcode]
' comment
Rem remark
[/vbcode]
-
Aug 18th, 2002, 02:19 PM
#13
Software Eng.
Did my code with TerminateProcess work?
-
Aug 18th, 2002, 02:55 PM
#14
Hyperactive Member
Oafo:not at all,please look at and test WriteProcessMemory with OpenProcess before you say it won't work. but there should be an easier way to do it.
-
Aug 19th, 2002, 03:53 PM
#15
Thread Starter
Hyperactive Member
Megatron: I still haven't tested it but I'll let ya know.
snakeeyes: I didn't say it wouldn't work, I just said it would be slow.
[vbcode]
' comment
Rem remark
[/vbcode]
-
Aug 19th, 2002, 11:09 PM
#16
Software Eng.
I just the following in MSDN
Terminating a process does not necessarily remove the process object from the system. A process object is deleted when the last handle to the process is closed.
So basically, if your process has any child processes, you might have to do a little extra work to get rid of it.
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
|