News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Terminate Process

Started by Force, May 12, 2012, 09:58:30 PM

Previous topic - Next topic

Force

I opened a txt file by using Shellexecute function before

and i wanna close it programatically

I wrote that project but Masm32 gives Error

"undefined symbol Process32First "

Even I could not test it if it will work or not

Is there a library mistake or did i make a mistake in that code ?
.386
.model flat, stdcall
option casemap :none   

; ###############################
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\shell32.inc
include \masm32\include\masm32rt.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\shell32.lib
     
; ################################

    .data
           buffer db "C://windows/notepad.exe",0
           opn db "open",0                   

    .data?
StartupInfo STARTUPINFO <>
ProcessInfo PROCESS_INFORMATION <>
hSnapshot    HANDLE ?
ProcEnt      PROCESSENTRY32 <?>
    .code

start:

invoke ShellExecute,0,addr opn,addr buffer,NULL,NULL,SW_SHOWNORMAL
invoke MessageBox,0,addr opn,0,0

;######################### TERMINATE PROCESS  ##############
invoke CreateToolhelp32Snapshot, TH32CS_SNAPPROCESS,0
mov hSnapshot,eax
mov [ProcEnt.dwSize],SIZEOF ProcEnt
invoke Process32First, hSnapshot,ADDR ProcEnt
invoke lstrcmpi, ADDR buffer ,ADDR [ProcEnt.szExeFile]
invoke OpenProcess, PROCESS_TERMINATE,FALSE,[ProcEnt.th32ProcessID]
invoke TerminateProcess, eax,0




  invoke ExitProcess,NULL

end start


Never Stop Until You Are Better Than The Best

jj2007


dedndave

here is how it is defined in kernel32.inc (masm32 v11)

Process32FirstW PROTO STDCALL :DWORD,:DWORD
IFDEF __UNICODE__
  Process32First equ <Process32FirstW>
ENDIF

Process32NextW PROTO STDCALL :DWORD,:DWORD
IFDEF __UNICODE__
  Process32Next equ <Process32NextW>
ENDIF


this is the post that Jochen mentioned
Quote from: -Alex- on March 14, 2012, 08:36:49 AM
For all others who have same prob like me before, here is simple solution:

Change in kernel32.inc

Process32FirstW PROTO STDCALL :DWORD,:DWORD
Process32NextW PROTO STDCALL :DWORD,:DWORD

to

Process32First PROTO STDCALL :DWORD,:DWORD
Process32Next PROTO STDCALL :DWORD,:DWORD

and make a new kernel32.lib or take the one from windows sdk.

that must be the old one (masm32 v10)
if you do it that way, it will break the unicode version

i would think this would be a better solution
Process32FirstW PROTO STDCALL :DWORD,:DWORD
IFDEF __UNICODE__
  Process32First equ <Process32FirstW>
ELSE
  Process32First PROTO STDCALL :DWORD,:DWORD
ENDIF

Process32NextW PROTO STDCALL :DWORD,:DWORD
IFDEF __UNICODE__
  Process32Next equ <Process32NextW>
ELSE
  Process32Next PROTO STDCALL :DWORD,:DWORD
ENDIF

Force

Dave  I tried

Process32FirstW PROTO STDCALL :DWORD,:DWORD
IFDEF __UNICODE__
  Process32First equ <Process32FirstW>
ELSE
  Process32First PROTO STDCALL :DWORD,:DWORD
ENDIF

Process32NextW PROTO STDCALL :DWORD,:DWORD
IFDEF __UNICODE__
  Process32Next equ <Process32NextW>
ELSE
  Process32Next PROTO STDCALL :DWORD,:DWORD
ENDIF


No error but it dsnt work

other side

Process32FirstW PROTO STDCALL :DWORD,:DWORD
Process32NextW PROTO STDCALL :DWORD,:DWORD

to

Process32First PROTO STDCALL :DWORD,:DWORD
Process32Next PROTO STDCALL :DWORD,:DWORD


then

error LNK2001: unresolved externalsymbol _Process32First@8
error LNK2001: unresolved externalsymbol _Process32Next@8

so  I need new kernel32.lib

Can I use masm32 sdk 10 kernel32.lib ?

Becouse i can assemle and link that code without error and it runs ( installed back masm32 sdk 10 already  :toothy )
Never Stop Until You Are Better Than The Best

dedndave

QuoteCan I use masm32 sdk 10 kernel32.lib ?

of course you can

but - i guess i would make a list of exports for both
then make a DEF file that has everything it should have
then make a new lib

or - if you are lazy, like me....
use GetProcAddress   :P

qWord

if you are lazy like Dave, you could also use the libs that comes with the Windows SDK  :dance:
FPU in a trice: SmplMath
It's that simple!

Force

I think I m lazy too Maybe Hutch will make new library later   :toothy
so I copied old kernel32.lib  and I changed kernel32.inc file

Now My Code is working

.386
.model flat, stdcall
option casemap :none   

; ###############################
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\shell32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\shell32.lib
     
; ################################

    .data
buffer db "C://windows/notepad.exe",0
opn db "open",0
kill db "Kill Process",0                   
target db"notepad.exe",0
    .data?
StartupInfo STARTUPINFO <>
ProcessInfo PROCESS_INFORMATION <>
hSnapshot    HANDLE ?
ProcEnt      PROCESSENTRY32 <?>

.code

start:

invoke ShellExecute,0,addr opn,addr buffer,NULL,NULL,SW_SHOWNORMAL
invoke MessageBox,0,addr kill,0,0

;######################### TERMINATE PROCESS  ##############
invoke CreateToolhelp32Snapshot, TH32CS_SNAPPROCESS,0
.IF (eax != INVALID_HANDLE_VALUE)
mov hSnapshot,eax
mov [ProcEnt.dwSize],SIZEOF ProcEnt
invoke Process32First, hSnapshot,ADDR ProcEnt

.IF (eax)
fix:
invoke lstrcmpi, ADDR target ,ADDR [ProcEnt.szExeFile]
.IF (eax == 0)
invoke OpenProcess, PROCESS_TERMINATE,FALSE,[ProcEnt.th32ProcessID]
.IF (eax)
invoke TerminateProcess, eax,0
.ENDIF
.ENDIF
invoke Process32Next, hSnapshot,ADDR ProcEnt
test eax,eax
jnz fix
.ENDIF
invoke CloseHandle, hSnapshot
.ENDIF
invoke ExitProcess,NULL
end start


Never Stop Until You Are Better Than The Best

hfheatherfox07

Hi there can you please include that modified .lib and .inc ?

Thank you

Nice work  :U

dedndave

i used Vortex's tools to create DEF files, added the 2 functions, then made LIB's
i want to post them - but they are ~1/3 the size of the ones Hutch has in masm v11
so - if Hutch or Erol pop in and explain why that is, i may post them   :P

Force

Thats great Dave

do you mean you may post Libs after Hutch's permission ?
If so
hope he will allow you
Never Stop Until You Are Better Than The Best

hfheatherfox07

Well Hutch might not like this but I use Universal Extractor  http://legroom.net/software/uniextract/ 

Download non install version : http://legroom.net/scripts/download.php?file=uniextract161_noinst

And extract one of the older versions of MASM and just copy the proc you need from the library before it gets assembled ....
I saw the example of setting .bmp to desktop background and I want to do one with .GIF so I need the proc that sets the desktop background and convert it to set .GIF


dedndave

it's easy to do, really
Erol's tools are great   :U
http://www.vortex.masmcode.com/

i used lib2def to create DEF files from the current libraries (kernel32.lib and kernl32p.lib, masm32 v11)
then, i added the 2 missing functions into both DEF files
(by the way - they sure enough are missing - and present in the masm32 v10 LIB's)
then, i used def2lib to create 2 new libraries

the reason i am not posting is this...
the new libraries i created by this method are about one third the size of the ones Hutch has in masm32 v11
so - before i post them, i want to know if i did something wrong   :red

i am sure there is a reason for the original files being larger
let's find out what it is

Force

Wooow thats good Thanks Dave
I think i can fix lib with it  :U

hfheatherfox07
I just used old masm32 v10 lib

Lib2def converter is the best way to create a library
Never Stop Until You Are Better Than The Best

dedndave

i think Hutch uses Japheth's inc2lib
and, while that may explain why the files are different - it does not explain why they are so vastly different - lol

dedndave

now - change the include files...
Process32FirstW PROTO STDCALL :DWORD,:DWORD
IFDEF __UNICODE__
  Process32First equ <Process32FirstW>
ELSE
  Process32First PROTO STDCALL :DWORD,:DWORD
ENDIF

Process32NextW PROTO STDCALL :DWORD,:DWORD
IFDEF __UNICODE__
  Process32Next equ <Process32NextW>
ELSE
  Process32Next PROTO STDCALL :DWORD,:DWORD
ENDIF

and you should be ready to rock