[RMXP] Kill a process on windows by RGSS

Started by Guilink, November 20, 2014, 11:06:33 am

Previous topic - Next topic

Guilink

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.
Waiting for BABS Controller for RMX-OS update! '-'

www.manaextreme.blogspot.com (my brazilian game-newblog)

Heretic86

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?
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

G_G

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.

KK20

I didn't look into it much, but it seems this would be really easy to do if it were on Linux.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Heretic86

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
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

Zexion

All i know is that it used to say the same exact thing when I would play pokemon remexos

Guilink


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
Waiting for BABS Controller for RMX-OS update! '-'

www.manaextreme.blogspot.com (my brazilian game-newblog)

ForeverZer0

November 21, 2014, 12:52:35 pm #7 Last Edit: November 21, 2014, 01:43:13 pm by ForeverZer0
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.

Spoiler: ShowHide
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)
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Guilink

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.

Spoiler: ShowHide
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:
Waiting for BABS Controller for RMX-OS update! '-'

www.manaextreme.blogspot.com (my brazilian game-newblog)

ForeverZer0

November 24, 2014, 11:52:58 am #9 Last Edit: November 24, 2014, 11:54:14 am by ForeverZer0
I think something like this should be sufficient for what you are trying to accomplish.

Spoiler: ShowHide
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
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Guilink

November 24, 2014, 04:34:48 pm #10 Last Edit: November 24, 2014, 07:26:13 pm by Guilink
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.

Spoiler: ShowHide
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 ?
Waiting for BABS Controller for RMX-OS update! '-'

www.manaextreme.blogspot.com (my brazilian game-newblog)

ForeverZer0

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 am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Guilink

November 25, 2014, 06:45:41 am #12 Last Edit: December 11, 2014, 06:34:21 am by Guilink
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
Waiting for BABS Controller for RMX-OS update! '-'

www.manaextreme.blogspot.com (my brazilian game-newblog)