News:

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

CreateProcess: MOD_NOT_FOUND Error

Started by EarlCrapstone, November 18, 2005, 03:49:14 AM

Previous topic - Next topic

EarlCrapstone

Whenever I try to do CreateProcess, it gives me an error "MOD_NOT_FOUND". This is the line of code I'm using:

invoke CreateProcess,NULL,addr process,NULL,NULL,TRUE,0,NULL,NULL,addr si_info,addr pi_info

Where process is "cmd.exe".

Why does it give me this error and how can I fix it?

hutch--

Try specifying the full path to CMD.EXE as long as you are running NT, 2K or later otherwise MD.EXE is not available on earlier versions.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

EarlCrapstone

Shouldn't cmd.exe be enough?

lpCommandLine
    [in, out] Pointer to a null-terminated string that specifies the command line to execute. The maximum length of this string is 32K characters.

It seems all I need to specify is the command to execute on the command line and that is "cmd.exe". I don't want to have to specify the whole path because it can be different on different machines.

Tedd

No snowflake in an avalanche feels responsible.

EarlCrapstone

With ShellExecute, don't you have to use the full path to the exe?

PBrennick

If you use %SystemRoot%\, it will correctly expand to c:\windows\ or c:\winnt\ or whatever.  This will solve the problem of cmd.exe being in differing places on differing machines.

so, %SystemRoot%\system32\cmd.exe could expand to c:\windows\system32\cmd.exe or c:\winnt\system32\cmd.exe depending on the installation.

hth,
Paul
The GeneSys Project is available from:
The Repository or My crappy website

tenkey

And if you want to use CreateProcess, then GetSystemDirectory will get you the directory where cmd.exe resides.

MSDN web site says this old-fashion call should be replaced by a call to SHGetFolderPath. There is a CSIDL_SYSTEM constant that can be used to get the system folder path.
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8

EarlCrapstone

If I give CreateProcess the full path of cmd.exe, it doesn't give any errors, but it doesn't start cmd.exe and when I debug it in Olly, it stops at some "repne" line right after CreateProcessA is called.

Tedd

..voila!

.386
.model flat, stdcall
option casemap:none
include windows.inc
include kernel32.inc
includelib kernel32.lib
include shell32.inc
includelib shell32.lib

.data
cmd_exe db "cmd.exe",0

.code
start:
    invoke ShellExecute, NULL,NULL,ADDR cmd_exe,NULL,NULL,SW_SHOWNORMAL
    invoke ExitProcess, NULL
end start


(You may want to fill in some of the other parameters, for parent window and default directory)
And obviously it will only work on machines where cmd.exe is available ::)
No snowflake in an avalanche feels responsible.

EarlCrapstone

I want to use CreateProcess over ShellExecute because I need to use si to capture the output on the screen when I execute commands like ipconfig or netstat.

And I really want to know what that mod not found error means. What causes it?

Tedd

Add your whole program and we'll take a look :U
No snowflake in an avalanche feels responsible.

EarlCrapstone

I haven't done anything else to the program except the CreateProcess part. I put a MessageBox in there to show the return value, but it returns NULL.


.486
.model flat, stdcall
option casemap :none
StartCmd proto

; includes

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib

.data

cmdexe db "cmd.exe",0

.code

start:

invoke StartCmd
invoke ExitProcess,eax

StartCmd Proc

LOCAL stin:STARTUPINFO
LOCAL prin:PROCESS_INFORMATION

mov stin.cb,sizeof stin
mov stin.wShowWindow,SW_HIDE
mov stin.dwFlags,STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW

invoke CreateProcess,NULL,addr cmdexe,NULL,NULL,TRUE,0,NULL,NULL,addr stin,addr prin

invoke MessageBox,NULL,eax,0,MB_OK

invoke CloseHandle,prin.hProcess
invoke CloseHandle,prin.hThread

ret

StartCmd endp

end start

PBrennick

EarlCrapstone,
Here is a program I picked up somewhere that uses CreateProcess to start cmd.exe


.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib

MyProc PROTO

.DATA
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CommandLine db "cmd.exe",0
;
.CODE
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
start:

invoke MyProc
invoke ExitProcess,0



MyProc PROC

LOCAL rect:RECT
LOCAL hRead:DWORD
LOCAL hWrite:DWORD
LOCAL hRead2:DWORD
LOCAL hWrite2:DWORD
LOCAL startupinfo:STARTUPINFO
LOCAL pinfo:PROCESS_INFORMATION
LOCAL buffer[1024]:byte
LOCAL buffer2[1024]:byte
LOCAL bytesRead:DWORD
LOCAL bytesWritten:DWORD
LOCAL hdc:DWORD
LOCAL sat:SECURITY_ATTRIBUTES

mov sat.nLength,sizeof SECURITY_ATTRIBUTES
mov sat.lpSecurityDescriptor,NULL
mov sat.bInheritHandle,TRUE
invoke CreatePipe,addr hRead,addr hWrite,addr sat,NULL
invoke CreatePipe,addr hRead2,addr hWrite2,addr sat,NULL
mov startupinfo.cb,sizeof STARTUPINFO
invoke GetStartupInfo,addr startupinfo
mov eax, hWrite
mov startupinfo.hStdOutput,eax
mov startupinfo.hStdError,eax
mov startupinfo.dwFlags, STARTF_USESHOWWINDOW+ STARTF_USESTDHANDLES
mov startupinfo.wShowWindow,SW_HIDE
invoke CreateProcess, NULL, addr CommandLine, NULL, NULL, TRUE, NULL, NULL, NULL, addr startupinfo, addr pinfo

invoke CloseHandle,hWrite
.while 1
.while TRUE
invoke RtlZeroMemory,addr buffer,1024
invoke ReadFile,hRead,addr buffer,1023,addr bytesRead,NULL
.if eax==NULL
.break
.endif
invoke StdOut,addr buffer
.endw
invoke CloseHandle,hRead2
.while TRUE
invoke RtlZeroMemory,addr buffer2,1024
invoke StdIn,addr buffer2,sizeof buffer2
invoke WriteFile,hWrite2,addr buffer2,sizeof buffer2,addr bytesWritten,NULL
.IF eax==NULL
.break
.endif
.endw
.endw
invoke ExitProcess,0
invoke CloseHandle,hRead
invoke CloseHandle,hWrite
ret

MyProc ENDP

end start


EDIT:  Added a batch file to build the project.

hth,
Paul


[attachment deleted by admin]
The GeneSys Project is available from:
The Repository or My crappy website

EarlCrapstone

Hmmm. If I try to recompile pipe.asm with no changes, the new pipe.exe does not execute cmd.exe and gives the error MOD_NOT_FOUND. The problem must be on my side, but I don't know what it could be.

EDIT: If I try to compile it with the batch file it works fine. The problem was that I was compiling it like a regular exe file, but it's a console exe. When I run it though, cmd.exe does not show up in task manager as running. Is it suppose to do that? When I compile mine as a console app, I can't tell if cmd.exe is actually started. When I debug it, it still stops on a "rep" line, so I don't think its working.

PBrennick

Earl,
It sounds to me like your path variable is incorrect, corrupt or missing.  Go to the Device Manager, Advainced, then Environment Variables and scope it out.

Mine looks like this...
Quote
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;D:\PBWin80\BIN;D:\PBCC40\BIN

hth,
Paul
The GeneSys Project is available from:
The Repository or My crappy website