Hello Everyone,
I look for a code to check whether there is an open process in windows. So I can finish the game if it is open .
Example:
If "cheatengine.exe" process is open
close game
end
I would be grateful if someone could help me with this
Thank and sorry for the bad english.
Cheat Engine would just look for "game.exe" (not always), but if you mean a Window like a Message Window, inside RMXP, then its a variable called $game_temp.message_window_showing. Does that help?
He's wanting to prevent his game from running while Cheat Engine is open. He's trying to figure out how to check if a particular process is showing, if so, close the game.
I didn't look into it much, but it seems this would be really easy to do if it were on Linux.
Oh, okay, now I see what is going on. My bad, dont answer tech questions before coffee.
Start > Run > Cmd tasklist
I know it cant be done, but not sure how to run "tasklist" from the command line as its own Anti Cheat Script. Perhaps something with WinAPI? Then its just a simple matter of checking those processes
tasklist = eval("WinAPI something tasklist")
for task in tasklist
if task.gsub(/^cheatengine.exe/i)
print "no cheating"
# Quit the game
exit
end
end
All i know is that it used to say the same exact thing when I would play pokemon remexos
Thanks everyone for the help.. I think we are on the right track.
I have this code that identifies an open window . But it is not enough
class Anti_HackTest
def initialize
findWindow = Win32API.new('user32.dll', 'FindWindow', 'P''P', 'L')
@Pro_N = [
findWindow.call(0, 'Cheat'),
#findWindow.call(0, 'Window name here'),
]
for i in 0... @Pro_N.size
if @Pro_N >= 1
print "No cheating ! The game will be closed"
exit
end
end
end
end
Not exactly the right track, a window handle is not a process. A process may not even have a window handle, so you will need to identify by the PID.
I might get a spare second soon, and see if I can throw together a couple Win32API functions you can use.
EDIT:
Have to go to work now, might work on this more later, but if someone feels like continuing and finishing, be my guest.
Here is how to get an array of all PIDs currently running.
enumprocesses = Win32API.new ('psapi.dll', 'EnumProcesses', 'plp', 'i')
pids = [0].pack ("L") * 1024
cbNeeded = [0].pack ("L")
enumprocesses.call(pids, 1024, cbNeeded)
num_procs = cbNeeded.unpack("L")[0] / 4
pids = pids.unpack("L" * num_procs)
Quote from: ForeverZer0 on November 21, 2014, 12:52:35 pm
Not exactly the right track, a window handle is not a process. A process may not even have a window handle, so you will need to identify by the PID.
I might get a spare second soon, and see if I can throw together a couple Win32API functions you can use.
EDIT:
Have to go to work now, might work on this more later, but if someone feels like continuing and finishing, be my guest.
Here is how to get an array of all PIDs currently running.
enumprocesses = Win32API.new ('psapi.dll', 'EnumProcesses', 'plp', 'i')
pids = [0].pack ("L") * 1024
cbNeeded = [0].pack ("L")
enumprocesses.call(pids, 1024, cbNeeded)
num_procs = cbNeeded.unpack("L")[0] / 4
pids = pids.unpack("L" * num_procs)
Thanks! With that he checks the amount of open process ...
Now I need to find a way to recognize the process by name :wacko:
I think something like this should be sufficient for what you are trying to accomplish.
module Zer0
#-----------------------------------------------------------------------------
# * Constants
#-----------------------------------------------------------------------------
EnumProcesses = Win32API.new ('psapi', 'EnumProcesses', 'plp', 'i')
OpenProcess = Win32API.new('kernel32', 'OpenProcess', 'lil', 'l')
GetProcessImageFileName =
Win32API.new('psapi', 'GetProcessImageFileName', 'lpl', 'l')
#-----------------------------------------------------------------------------
# * Get Array of Running Executables on the System
#-----------------------------------------------------------------------------
def self.executable_names
exes = []
pids = self.process_ids
pids.each {|pid|
handle = OpenProcess.call(0x0400, 0, pid)
next if handle == 0
buffer = "\0" * 256
result = GetProcessImageFileName.call(handle, buffer, 256)
next if result == 0
exe = buffer.delete("\0").split('\\').pop
exes.push(exe)
}
return exes
end
#-----------------------------------------------------------------------------
# * Get Array of IDs of Processes Running on the System
#-----------------------------------------------------------------------------
def self.process_ids
pids = [0].pack ('L') * 1024
bytes = [0].pack ('L')
EnumProcesses.call(pids, 1024, bytes)
count = bytes.unpack('L')[0] / 4
return pids.unpack('L' * count)
end
#-----------------------------------------------------------------------------
# * Check if Specified Executable(s) is Running
#-----------------------------------------------------------------------------
def self.check_exe(*names)
exes = self.executable_names
names.each {|name| return true if exes.include?(name) }
return false
end
end
It basically allows to check for the executable name of running processes. With that, you can do your own checks on names and compare. I will leave it to you to expand on that aspect of it, although I did make a basic function at the end to demonstrate a simple way. If you need any help using or understanding it, just ask.
I haven't tested anything yet, so I am not sure if it is possible to change the exe name to fool the script. If so, might need to change how it works a little bit. I just went for the quick and simple way of getting it done.
EDIT:
Wow, it has been a long time since I have written code using Ruby... :P
Quote from: ForeverZer0 on November 24, 2014, 11:52:58 am
I think something like this should be sufficient for what you are trying to accomplish.
module Zer0
#-----------------------------------------------------------------------------
# * Constants
#-----------------------------------------------------------------------------
EnumProcesses = Win32API.new ('psapi', 'EnumProcesses', 'plp', 'i')
OpenProcess = Win32API.new('kernel32', 'OpenProcess', 'lil', 'l')
GetProcessImageFileName =
Win32API.new('psapi', 'GetProcessImageFileName', 'lpl', 'l')
#-----------------------------------------------------------------------------
# * Get Array of Running Executables on the System
#-----------------------------------------------------------------------------
def self.executable_names
exes = []
pids = self.process_ids
pids.each {|pid|
handle = OpenProcess.call(0x0400, 0, pid)
next if handle == 0
buffer = "\0" * 256
result = GetProcessImageFileName.call(handle, buffer, 256)
next if result == 0
exe = buffer.delete("\0").split('\\').pop
exes.push(exe)
}
return exes
end
#-----------------------------------------------------------------------------
# * Get Array of IDs of Processes Running on the System
#-----------------------------------------------------------------------------
def self.process_ids
pids = [0].pack ('L') * 1024
bytes = [0].pack ('L')
EnumProcesses.call(pids, 1024, bytes)
count = bytes.unpack('L')[0] / 4
return pids.unpack('L' * count)
end
#-----------------------------------------------------------------------------
# * Check if Specified Executable(s) is Running
#-----------------------------------------------------------------------------
def self.check_exe(*names)
exes = self.executable_names
names.each {|name| return true if exes.include?(name) }
return false
end
end
It basically allows to check for the executable name of running processes. With that, you can do your own checks on names and compare. I will leave it to you to expand on that aspect of it, although I did make a basic function at the end to demonstrate a simple way. If you need any help using or understanding it, just ask.
I haven't tested anything yet, so I am not sure if it is possible to change the exe name to fool the script. If so, might need to change how it works a little bit. I just went for the quick and simple way of getting it done.
EDIT:
Wow, it has been a long time since I have written code using Ruby... :P
Thank you! Is perfect!
It worked, I called by this way :
if Zer0::check_exe("notepad.exe")
print "Notepad is open"
else
print "Notepad is Close"
end
But one thing , when I tested at the morning on office computer (Win 7) worked perfectly , as when I tested at home now (Win XP ) did not work properly ... the list of exes appeared incorrectly, it interferes with something ?
There is a difference in the methods between the two operating systems, so I will need to make an edit to identify the OS and have it behave accordingly.
Quote from: ForeverZer0 on November 24, 2014, 07:55:58 pm
There is a difference in the methods between the two operating systems, so I will need to make an edit to identify the OS and have it behave accordingly.
I understand.
If you can do only for WinXP/Seven already'll be perfect for me.
I have to admit, my project depends on it.
Anyway, thank you already helped me a lot.
EDIT:Please if someone else can adapt to Windows XP will be very grateful