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 


PID getProcessIDFromProcessName

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
samy_grecu
!BEWARE! Deletes post on answer
Reputation: 0

Joined: 30 Dec 2016
Posts: 12
Location: Italy

PostPosted: Mon Jan 22, 2018 7:31 am    Post subject: PID getProcessIDFromProcessName Reply with quote

Hi
I try to print also the PID like this "Attached to Tutorial: .. PID ..")
Can anyone help me
Code:
PROCESS_NAME = 'Tutorial-i386.exe'
--------
-------- Auto Attach
--------
local autoAttachTimer = nil
local autoAttachTimerInterval = 1000 ---- Timer intervals are in milliseconds
local autoAttachTimerTicks = 0
local autoAttachTimerTickMax = 5000 ---- Set to zero to disable ticks max
local function autoAttachTimer_tick(timer) ---- Timer tick call back
   if autoAttachTimerTickMax > 0 and autoAttachTimerTicks >= autoAttachTimerTickMax then
      timer.destroy() ---- Destroy timer if max ticks is reached
   end
   if getProcessIDFromProcessName(PROCESS_NAME) ~= nil then ---- Check if process is running
     CETrainer.Caption = "Tutorial-i386.exe not running !"
      timer.destroy() ---- Destroy timer
      openProcess(PROCESS_NAME) ---- Open the process
    CETrainer.Caption = "Attached to Tutorial-i386.exe"
   end
   autoAttachTimerTicks = autoAttachTimerTicks + 1 ---- Increase ticks
end
autoAttachTimer = createTimer(getMainForm()) ---- Create timer with the main form as it's parent
autoAttachTimer.Interval = autoAttachTimerInterval ---- Set timer interval
autoAttachTimer.OnTimer = autoAttachTimer_tick ---- Set timer tick call back
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Mon Jan 22, 2018 7:35 am    Post subject: Reply with quote

Code:
-- note these do not update if the process closes
-- to check if open you can use readInteger(process) ~= nil
-- that way if there are multiple instances of the same program
-- you know that the one CE _was_ attached to is or is not still running
-- without explicitly checking that the process ids match
if process ~= nil then
  use getOpenedProcessID()
end


though I'm not sure why you'd only wait five seconds....also, you could use

Code:
onOpenProcess = function(pid)
  do stuff when CE attaches to a process
end
Back to top
View user's profile Send private message
samy_grecu
!BEWARE! Deletes post on answer
Reputation: 0

Joined: 30 Dec 2016
Posts: 12
Location: Italy

PostPosted: Mon Jan 22, 2018 10:34 am    Post subject: Reply with quote

thank you..

i use the code for multiple browsers in my trainers
the problem is that I am forced to use autoAttachTimerInterval
to check if the browser closed and reopened(
all work fine, but my pc gets very slow
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting 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