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 


Find Specific Process When Duplicate Names Exist

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Fri Sep 09, 2016 3:41 pm    Post subject: Find Specific Process When Duplicate Names Exist This post has 1 review(s) Reply with quote

Cheat Engine gives you the ability to enumerate each module used within a specific process.
This can allow you to uniquely identify one process among multiples with the same name.

The following script will print a list of all modules used by the currently attached process.
Use this to find a specific module that only the correct process contains.
Code:
local modules = enumModules()
for j = 1, #modules do
  print(modules[j].Name)
end


The following function accepts two parameters: a process name and a module name.
It will return the unique identifier of the process matching the supplied names.
Code:
function findProcessWithModule(processName, moduleName)
  local processes = createStringlist()
  getProcesslist(processes)
  for i = processes.Count - 1, 0, -1 do
    local found = processes[i]:find(processName)
    if found ~= nil then
      local processId = processes[i]:sub(0, found - 2)
      local modules = enumModules(processId)
      for j = 1, #modules do
        if modules[j].Name == moduleName then
          processes.Destroy()
          return tonumber(processId, 16)
        end
      end
    end
  end
  processes.Destroy()
end


You can directly open a process utilizing its process identifier.
Code:
local processId = findProcessWithModule("Calculator.exe", "user32.dll")
if processId ~= nil then
  openProcess(processId)
end


If you would like your table to automatically detect when this process exists, you can implement a timer.
Code:
if mytimer == nil then
  mytimer = createTimer(nil, false)
end
mytimer.Interval = 1000
mytimer.OnTimer = function(timer)
  local processId = findProcessWithModule("Calculator.exe", "user32.dll")
  if processId ~= nil then
    mytimer.Enabled = false
    openProcess(processId)
  end
end
mytimer.Enabled = true


Last edited by Zanzer on Fri Sep 09, 2016 6:24 pm; edited 1 time in total
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 958

PostPosted: Fri Sep 09, 2016 6:15 pm    Post subject: Reply with quote

When enumerate the process using getProcesslist(processes) , it seems the list order follow the time of opening, that's later process opened will have higher index in the list, most lower index process are system process etc.

It may be a bit efficient to find target process by reversing the process for loop.

bye~

_________________
- Retarded.
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Fri Sep 09, 2016 6:24 pm    Post subject: Reply with quote

Reversed.
Back to top
View user's profile Send private message
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