The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Magnum on April 17, 2010, 11:08:39 PM

Title: error_mod_not_found
Post by: Magnum on April 17, 2010, 11:08:39 PM
I got an error_mod_not_found on this file.
New one for me.

Can someone help me fix this.
The works fine in a batch file, so it should work.


; error_mod_not_found
; Delete_ALL.asm Open a cmd window
;  deltree.exe Deletes a directory and all the subdirectories and              files in it.
;
; To delete one or more files and directories:
; DELTREE [/Y] [drive:]path [[drive:]path[...]]
;
;   /Y              Suppresses prompting to confirm you want to delete
;                   the subdirectory.
;   [drive:]path    Specifies the name of the directory you want to delete.
;
; Note: Use DELTREE cautiously. Every file and subdirectory within the
; specified directory will be deleted.
;                               
;
.386
.MODEL FLAT, STDCALL
OPTION CASEMAP: NONE


    include \masm32\include\windows.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc
    include \masm32\include\advapi32.inc
    include \masm32\include\shlwapi.inc
    include \masm32\include\shell32.inc
    include \masm32\macros\macros.asm

    includelib  \masm32\lib\kernel32.lib
    includelib  \masm32\lib\user32.lib
    includelib  \masm32\lib\advapi32.lib
    includelib  \masm32\lib\shlwapi.lib
    includelib  \masm32\lib\shell32.lib

BREAK equ int 1h ;Breakpoint for debugging apps

.DATA

szOpen    DB "open",0
cmd       DB "C:\Spec_Progs\deltree.exe",0
params    db "/Y C:\Documents and Settings\LU\Local Settings\Temp",0
directory db "C:",0

.CODE

Internal_Notes  db "A.K. 2010"

start:

invoke ShellExecute,NULL,NULL,OFFSET cmd,offset params,OFFSET directory,SW_SHOW

invoke ExitProcess,0

end start

Title: Re: error_mod_not_found
Post by: clive on April 18, 2010, 12:37:45 AM
Quote from: Magnum
params    db "/Y C:\Documents and Settings\LU\Local Settings\Temp",0

You might want to put paths with spaces in quotes.

params    db "/Y ""C:\Documents and Settings\LU\Local Settings\Temp""",0

-Clive
Title: Re: error_mod_not_found
Post by: MichaelW on April 18, 2010, 05:23:08 AM
Quote from: clive on April 18, 2010, 12:37:45 AM
You might want to put paths with spaces in quotes.

params    db "/Y ""C:\Documents and Settings\LU\Local Settings\Temp""",0


That will assemble, but the passed command line is broken after the /F. This syntax will assemble and pass the entire command line (note that I had to place the space after the /Y inside the inner quotes):

params    db '/Y" C:\Documents and Settings\LU\Local Settings\Temp"',0

Title: Re: error_mod_not_found
Post by: joemc on April 18, 2010, 06:12:58 AM
makes more sense to me to write as:

params    db "/Y ",22h,"C:\Documents and Settings\LU\Local Settings\Temp",22h,0

and i would pass a NULL or C:\ instead of C: for lpDirectory. 
Quote from: MSDN
pDirectory [in, optional]
LPCTSTR
A pointer to a null-terminated string that specifies the default (working) directory for the action. If this value is NULL, the current working directory is used. If a relative path is provided at lpFile, do not use a relative path for lpDirectory.
Title: Re: error_mod_not_found
Post by: sinsi on April 18, 2010, 06:31:02 AM
You might look at SHFileOperation to delete files, not sure about directories though.
Title: Re: error_mod_not_found
Post by: MichaelW on April 18, 2010, 06:32:26 AM
Quote from: joemc on April 18, 2010, 06:12:58 AM
makes more sense to me to write as:

params    db "/Y ",22h,"C:\Documents and Settings\LU\Local Settings\Temp",22h,0

The passed command line is broken after the /Y. My problem with that syntax is that it requires you to know the character code for a double quote.
Title: Re: error_mod_not_found
Post by: joemc on April 18, 2010, 06:36:50 AM
Quote from: MichaelW on April 18, 2010, 06:32:26 AM
The passed command line is broken after the /Y.
Thats seems like a strange way for them to parse the string.
i will have to test but maybe:
db 22h,"/Y ",22h,"C:\Documents and Settings\LU\Local Settings\Temp",22h,22h,0

Quote from: MichaelW on April 18, 2010, 06:32:26 AM
My problem with that syntax is that it requires you to know the character code for a double quote.
I can't get ASCII out of my head, wish that it were a problem for me. Maybe an EQU would make it cleaner though. or a comment.
Title: Re: error_mod_not_found
Post by: MichaelW on April 18, 2010, 06:53:39 AM
For:

db 22h,"/Y ",22h,"C:\Documents and Settings\LU\Local Settings\Temp",22h,22h,0

The passed command line is:

/Y C:\Documents
Title: Re: error_mod_not_found
Post by: sinsi on April 18, 2010, 07:04:34 AM
Just use the ' character to enclose the whole thing and use the " character as the literal in the command line.
db '/y "C:\Documents and Settings\LU\Local Settings\Temp"',0
The /y doesn't need to be in quotes but any path with spaces does.

Of course if you don't have access to that path it won't work anyway.
Title: Re: error_mod_not_found
Post by: joemc on April 18, 2010, 07:17:59 AM
To avoid the shellexec I would just stick to FindFirstFile http://msdn.microsoft.com/en-us/library/aa364418(VS.85).aspx
and DeleteFile http://msdn.microsoft.com/en-us/library/aa363915(VS.85).aspx
and if desire RemoveDirectory http://msdn.microsoft.com/en-us/library/aa365488(VS.85).aspx
that way you know what your program is doing. shell exec could do anything if the target has been modified and creates an unnecessary process.

Sinsi,
I believe that would be the same as my first attempt.
Title: Re: error_mod_not_found
Post by: MichaelW on April 18, 2010, 07:24:22 AM
Quote from: sinsi on April 18, 2010, 07:04:34 AM
The /y doesn't need to be in quotes but any path with spaces does.

It looks to me like the /Y is part of the command line that needs to be passed to deltree. For my tests I coded an app that displays its command line, named it deltree.exe and placed it on the specified path. I then ran the posted code to see what command line ShellExecute is passing. So far, my syntax is the only one that will pass the entire command line.

Title: Re: error_mod_not_found
Post by: joemc on April 18, 2010, 07:35:42 AM
perhaps the proper way would be

szOpen    DB "open",0
cmd       DB "C:\Spec_Progs\deltree.exe",0               
params    db "/Y \Temp*",0       ; can't imagine would need to be db 22h,"/Y \Temp*",22h,0   
directory db 22h,"C:\Documents and Settings\LU\Local Settings\",22h,0
Title: Re: error_mod_not_found
Post by: clive on April 18, 2010, 02:11:43 PM
Here's how the original, and my paired double quote method work with the standard MSVC command line parser. I'll note that the paired double quote method is one that has worked in a great many computer languages since '82. As such I'd classify it as one of the more portable methods. Of course you have to understand it, but that's true of many techniques and representations. It is agnostic to ASCII, EBCDIC, etc encoding, and languages where the single quote means something else. Paired single quotes should also work.

ARG : 'ARGV[ARG]'
0 : 'z:\dev\asm\args.exe'
1 : '/Y'
2 : 'C:\Documents'
3 : 'and'
4 : 'Settings\LU\Local'
5 : 'Settings\Temp'


0 : 'z:\dev\asm\args.exe'
1 : '/Y'
2 : 'C:\Documents and Settings\LU\Local Settings\Temp'


-Clive
Title: Re: error_mod_not_found
Post by: Magnum on April 18, 2010, 02:21:23 PM
Quote from: sinsi on April 18, 2010, 06:31:02 AM
You might look at SHFileOperation to delete files, not sure about directories though.

You get the gold star. I didn't like the clunky ShellExecute anyway.  :lol


; Delete_ALL.asm 
;              Help from Sinsi,Hutch,Clive,joemc,Michael,
;
    .486                       ; create 32 bit code
    .model flat, stdcall       ; 32 bit memory model
    option casemap :none       ; case sensitive

    include \masm32\include\windows.inc
    include \masm32\include\masm32.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc
    include \masm32\include\shell32.inc
    includelib \masm32\lib\masm32.lib
    includelib \masm32\lib\user32.lib
    includelib \masm32\lib\kernel32.lib
    includelib \masm32\lib\shell32.lib
    include \masm32\macros\macros.asm

    RecycleFile PROTO :DWORD

    .data

  fname1 db "C:\Documents and Settings\LU\Local Settings\Temp",0,0     
             
  buffer  db 30 dup (0)     

    .code

start:
     
    invoke RecycleFile,ADDR fname1

    push eax
    invoke GetLastError
    invoke dw2a,eax,ADDR buffer
    print SADD(13,10,"GetLastError returned ")
    print ADDR buffer
    pop eax
    invoke ExitProcess,0

; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
; This proc calls the SHFileOperation function to delete
; the specified file or files to the recycle bin. Each file
; must be specified with a fully qualified path (otherwise,
; the file will simply be deleted, without being placed in
; the recycle bin). Multiple files can specified by
; separating the individual paths with a null, and appending
; an additional null to the end of the final path.
;
; Returns zero for success, or nonzero for failure.
;
; Initializing the hwnd element to NULL proved to be
; necessary so the SHFileOperation function could delete
; a file that was created by the calling process.
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
RecycleFile proc pszFullPath:DWORD
    LOCAL fo:SHFILEOPSTRUCT
   
    mov fo.hwnd,  NULL
    mov fo.wFunc, FO_DELETE
    m2m fo.pFrom, pszFullPath
    mov fo.pTo,   NULL
    mov fo.fFlags,FOF_ALLOWUNDO
    invoke SHFileOperation,ADDR fo

    ret
RecycleFile endp

end start

; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

; * Note WORD element *:

SHFILEOPSTRUCTA STRUCT
  hwnd                  DWORD      ?
  wFunc                 DWORD      ?
  pFrom                 DWORD      ?
  pTo                   DWORD      ?
  fFlags                FILEOP_FLAGS ?
  fAnyOperationsAborted DWORD      ?
  hNameMappings         DWORD      ?
  lpszProgressTitle     DWORD      ?
SHFILEOPSTRUCTA ENDS
FILEOP_FLAGS            typedef WORD



Title: Re: error_mod_not_found
Post by: MichaelW on April 18, 2010, 02:52:09 PM
Compiling my dummy app with the Microsoft Visual C++ 2003 Toolkit does not change my results. The /Y must be included within the paired quotes or the space following it will terminate the command line.
Title: Re: error_mod_not_found
Post by: Magnum on April 18, 2010, 03:00:00 PM
I put in some error code to be able to respond when the directory isn't there.
But it isn't working completely.

I am getting a "Cannot delete file: Cannot read from the source file or disk."


invoke RecycleFile,ADDR fname1
   
    .if eax != NULL
      invoke  MessageBox, NULL, addr msg_NotNT, addr AppName, MB_OK
      invoke  ExitProcess, NULL
    .endif
Title: Re: error_mod_not_found
Post by: dedndave on April 18, 2010, 03:07:00 PM
you might get that error if the file is in a ZIP or CAB, etc
Title: Re: error_mod_not_found
Post by: clive on April 18, 2010, 08:42:03 PM
Quote from: MichaelW on April 18, 2010, 02:52:09 PM
Compiling my dummy app with the Microsoft Visual C++ 2003 Toolkit does not change my results. The /Y must be included within the paired quotes or the space following it will terminate the command line.

That seems very odd, could you post the source/executable.

-Clive
Title: Re: error_mod_not_found
Post by: MichaelW on April 19, 2010, 01:45:53 AM
Quote from: clive on April 18, 2010, 08:42:03 PM
That seems very odd, could you post the source/executable.

Edit:

I finally woke up and realized that my test is not valid, because deltree is going to be looking for two arguments, not just one. And realizing that, I now recall making this same mistake several years ago.
Title: Re: error_mod_not_found
Post by: joemc on April 19, 2010, 02:36:29 AM
Basically what you want to do is provided at url below. except instead of print call DeleteFile and  RemoveDirectory
http://www.devasp.net/net/articles/display/652.html

Title: Re: error_mod_not_found
Post by: Magnum on April 19, 2010, 04:22:43 AM
Quote from: MichaelW on April 19, 2010, 01:45:53 AM
Quote from: clive on April 18, 2010, 08:42:03 PM
That seems very odd, could you post the source/executable.

Edit:

I finally woke up and realized that my test is not valid, because deltree is going to be looking for two arguments, not just one. And realizing that, I now recall making this same mistake several years ago.

I am confused with your attachment.

It has both an .asm file and a .c file.

How can I make your .exe that you have?

I already have deltree.exe.







Title: Re: error_mod_not_found
Post by: joemc on April 19, 2010, 04:42:13 AM
Magnum,
His deltree is just a dummy that was testing what ShellExecute was calling.
His edit is because he was just checking the first argument. not the whole command line

boils down to :

params    db "/Y ",22h,"C:\Documents and Settings\LU\Local Settings\Temp",22h,0
or as sinsi said:
db '/y "C:\Documents and Settings\LU\Local Settings\Temp"',0

should call it the same as your batch file did.

I personally would still write the code into your asm file instead of depending on a shell execute.
---------
a simple, short, and correct way to test command line in masm instead of C

include \masm32\include\masm32rt.inc
.code
start:
  call GetCommandLine
  print eax
  inkey
  exit
end start

Title: Re: error_mod_not_found
Post by: joemc on April 19, 2010, 05:44:22 AM
Went ahead and wrote it real quick. successfully deletes non in use temporary files and directories on my system.

include \masm32\include\masm32rt.inc

.DATA
shellex   db "cmd",0
param     db '/k rmdir /s/q "C:\Documents and Settings\Administrator\Local Settings\Temp" ',0
; Close CMD window when done instead of stay open
;param    db '/c rmdir /s/q "C:\Documents and Settings\Administrator\Local Settings\Temp" ',0

.CODE
start:
  invoke ShellExecute,NULL,NULL,OFFSET shellex,offset param, NULL,SW_SHOW
  inkey
  exit
end start


May be a little more useful if it ran for any user, but not what you asked for. Windows keeps the current user's temporary directory in an environmental variable called "TEMP".
GetEnvironmentVariable http://msdn.microsoft.com/en-us/library/ms683188(VS.85).aspx

include \masm32\include\masm32rt.inc

.DATA
temp      db "TEMP",0
shellex   db "cmd",0
param     db "/k rmdir /s/q "
directory db 0 dup(MAX_PATH+1)

.CODE
start:
  invoke GetEnvironmentVariable, OFFSET temp, OFFSET directory,MAX_PATH
  invoke ShellExecute,NULL,NULL,OFFSET shellex, OFFSET param, NULL,SW_SHOW
  inkey
  exit
end start
Title: Re: error_mod_not_found
Post by: clive on April 19, 2010, 03:16:43 PM
Quote from: MichaelW
I finally woke up and realized that my test is not valid, because deltree is going to be looking for two arguments, not just one. And realizing that, I now recall making this same mistake several years ago.

Fair enough. Generally when I'm trying to understand how an application is spawning another, I'd try to enumerate all parameters. There are enough cases where the ordering or number of parameters can be important. In some cases looking at the environment variables passed down can also be enlightening. @Magnum, using proxy applications to test the interaction is quite common, especially when the command DELETE, DELTREE, FORMAT, etc can be potentially destructive. It gives you some visibility which is otherwise difficult to achieve.

FreeDOS's deltree has several more options/switches
http://help.fdos.org/en/hhstndrd/base/deltree.htm

I'd tend to agree with Joe, I'd probably just implement it myself by traversing the tree (directory, registry, etc) and perform the operation directly, rather than spawn some third party application to do it. This can be quite useful if you are trying to log or debug the actions of your application at a more granular level.

-Clive
Title: Re: error_mod_not_found
Post by: Magnum on April 20, 2010, 02:17:51 AM
Quote from: joemc on April 19, 2010, 05:44:22 AM
Went ahead and wrote it real quick. successfully deletes non in use temporary files and directories on my system.

include \masm32\include\masm32rt.inc

.DATA
shellex   db "cmd",0
param     db '/k rmdir /s/q "C:\Documents and Settings\Administrator\Local Settings\Temp" ',0
; Close CMD window when done instead of stay open
;param    db '/c rmdir /s/q "C:\Documents and Settings\Administrator\Local Settings\Temp" ',0

.CODE
start:
  invoke ShellExecute,NULL,NULL,OFFSET shellex,offset param, NULL,SW_SHOW
  inkey
  exit
end start


Thanks, I used SHFileOperation to delete most directories.

I found a program call SetACL that should be able to let me view the system volume informtion directory.
It's  command line driven, but I can't figure out all the switches.

It's pretty complicated.