Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[VB6]

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
torpin005
Master Cheater
Reputation: 0

Joined: 19 Nov 2007
Posts: 255

PostPosted: Fri Jan 04, 2008 4:22 pm    Post subject: [VB6] Reply with quote

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
View user's profile Send private message AIM Address
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Fri Jan 04, 2008 6:46 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
torpin005
Master Cheater
Reputation: 0

Joined: 19 Nov 2007
Posts: 255

PostPosted: Fri Jan 04, 2008 8:32 pm    Post subject: Reply with quote

thats confusing
Back to top
View user's profile Send private message AIM Address
Elec0
Expert Cheater
Reputation: 0

Joined: 21 Nov 2007
Posts: 188
Location: Out of my mind, back in five minutes.

PostPosted: Fri Jan 04, 2008 9:12 pm    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Fri Jan 04, 2008 10:35 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
killersamurai
Expert Cheater
Reputation: 0

Joined: 10 Sep 2007
Posts: 197
Location: Colorado

PostPosted: Sat Jan 05, 2008 12:58 pm    Post subject: Reply with quote

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
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sat Jan 05, 2008 1:20 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
torpin005
Master Cheater
Reputation: 0

Joined: 19 Nov 2007
Posts: 255

PostPosted: Sun Jan 06, 2008 6:09 pm    Post subject: Reply with quote

omg it works thanks Wiccaan
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites