View previous topic :: View next topic |
Author |
Message |
torpin005 Master Cheater
Reputation: 0
Joined: 19 Nov 2007 Posts: 255
|
Posted: Fri Jan 04, 2008 4:22 pm Post subject: [VB6] |
|
|
Is there a way while my program is running that like say its a math program. If some one opened the computer calculator while my program was running is there a code to terminate the calculator?
|
|
Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Fri Jan 04, 2008 6:46 pm Post subject: |
|
|
You can use the CreateToolhelp32Snapshot API with Process32First/Process32Next to monitor for calc.exe in the running process list and then use TerminateProcess to kill the process if it is found.
Check out the MSDN on how to use those API if you don't know how to already.
_________________
- Retired. |
|
Back to top |
|
 |
torpin005 Master Cheater
Reputation: 0
Joined: 19 Nov 2007 Posts: 255
|
Posted: Fri Jan 04, 2008 8:32 pm Post subject: |
|
|
thats confusing
|
|
Back to top |
|
 |
Elec0 Expert Cheater
Reputation: 0
Joined: 21 Nov 2007 Posts: 188 Location: Out of my mind, back in five minutes.
|
Posted: Fri Jan 04, 2008 9:12 pm Post subject: |
|
|
Indeed. I would post an example of it, except I have no idea what he's talking about. (Could you post an example?)
_________________
|
|
Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Fri Jan 04, 2008 10:35 pm Post subject: |
|
|
I wrote a trainer toolkit a while back in VB and then rewrote it again to optimize it and such and released it open source recently which you can find here:
http://www.extalia.com/forums/viewtopic.php?f=22&t=2585
(Oh noes an Extalia link!)
The class file clsProcess makes use of the API I listed above. You can rework it, or use those classes in your project to do this fairly simple. Create a timer, or thread, and monitor the process list just have it loop constantly. I suggest putting a sleep in the thread if you use one, or give the timer an interval of 1-5 seconds to not pressure the system too much. Make use of DoEvents when possible if needed too.
_________________
- Retired. |
|
Back to top |
|
 |
killersamurai Expert Cheater
Reputation: 0
Joined: 10 Sep 2007 Posts: 197 Location: Colorado
|
Posted: Sat Jan 05, 2008 12:58 pm Post subject: |
|
|
I would also use FindWindow(). This would let you get the caption of the Window (Calculator) since it doesn't change. This way, if someone renames the .exe you still can detect it. But, it can still fail because you can edit that as well.
|
|
Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sat Jan 05, 2008 1:20 pm Post subject: |
|
|
Had some extra time on my hands this morning so heres a quick toss together of my suggestion:
Put this code into a module:
Code: | Option Explicit
'//
'// Constants
'//
Private Const MAX_PATH = 260
Private Const TH32CS_SNAPPROCESS = &H2
Private Const PROCESS_ALL_ACCESS As Long = &H1F0FFF
'//
'// Process Entry Type
'//
Private 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
'//
'// API Declarations
'//
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long)
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As Any) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As Any) As Long
'//============================================================================
'// @Function: ProcessScan
'// @Params : None
'// @Returns : None
'// @Purpose : Scans for calc.exe in the process list and if found,
'// terminates the running instance.
'//============================================================================
Public Sub ProcessScan()
Dim pe32 As PROCESSENTRY32
Dim hSnapshot As Long
Dim bFoundProc As Boolean
pe32.dwSize = Len(pe32)
hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
bFoundProc = Process32First(hSnapshot, pe32)
Do While bFoundProc
If Right$(LCase$(Left$(pe32.szexeFile, InStr(1, pe32.szexeFile, Chr(0)) - 1)), Len("calc.exe")) = LCase$("calc.exe") Then
'// Found calc.exe, terminating.
Dim hProcHandle As Long
hProcHandle = OpenProcess(PROCESS_ALL_ACCESS, False, pe32.th32ProcessID)
Call TerminateProcess(hProcHandle, 0)
Call CloseHandle(hProcHandle)
End If
bFoundProc = Process32Next(hSnapshot, pe32)
DoEvents
Loop
Call CloseHandle(hSnapshot)
End Sub |
Then in your main form, create a timer, set the interval to 1000 (for 1 second) and for the timer code:
Code: | Private Sub Timer1_Timer()
'//
'// Monitor Processes
'//
Call ProcessScan
End Sub |
_________________
- Retired. |
|
Back to top |
|
 |
torpin005 Master Cheater
Reputation: 0
Joined: 19 Nov 2007 Posts: 255
|
Posted: Sun Jan 06, 2008 6:09 pm Post subject: |
|
|
omg it works thanks Wiccaan
|
|
Back to top |
|
 |
|