Jump to content

Error checking help

- - - - -

  • Please log in to reply
6 replies to this topic

#1
Slider

Slider

    Learning Programmer

  • Members
  • PipPipPip
  • 33 posts
I want to give a message if the batch file is not present.

I left off the "t" in bat to point to a non-existent file.

My code isn't working.

Can someone help me?

Thanks,
Andy


start:


      invoke    GetStartupInfo, addr StartupInfo

    invoke    GetEnvironmentVariable, CTEXT('ComSpec'), addr szComspec, sizeof szComspec

    invoke    wsprintf, addr szAppname, CTEXT('"%s" /c "c:\Bat\J_Cruzer.ba"'), addr szComspec

    invoke    CreateProcess, 0, addr szAppname, 0, 0, FALSE, \

                NORMAL_PRIORITY_CLASS, 0, 0, addr StartupInfo, addr ProcessInfo

    

.IF EAX == 0

   invoke MessageBox, 0, ADDR No_Batch_File, ADDR AppName,MB_ICONINFORMATION

   invoke  ExitProcess,NULL


.ENDIF



invoke    WaitForSingleObject, ProcessInfo.hProcess, INFINITE


Edited by dargueta, 27 January 2011 - 11:41 AM.
Please use code tags next time.


#2
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,251 posts
  • Location:C:\Countries\US
What exactly is that code supposed to do? If you use CreateProcess(), maybe you could do something like, instead of calling "file.bat", call "C:\Windows\System32\cmd.exe" with "file.bat" as the second command-line argument? You could also use file functions, such as OpenFile(), to check if the file exists.

#3
Slider

Slider

    Learning Programmer

  • Members
  • PipPipPip
  • 33 posts
Thanks for you suggestions.

The bat file updates a thumb drive with newer files from my hard drive.

I wanted an custom icon with the program, thus building an executable was one way to do it.

Andy

#4
mebob

mebob

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 490 posts
Why don't you just use the Windows ShellExecute function? Check it out: ShellExecute Function (Windows). And if you are just making this program to run a batch file, consider using a higher level language like C.
Latinamne loqueris?

#5
Slider

Slider

    Learning Programmer

  • Members
  • PipPipPip
  • 33 posts

mebob said:

Why don't you just use the Windows ShellExecute function? Check it out: ShellExecute Function (Windows). And if you are just making this program to run a batch file, consider using a higher level language like C.

Here is my completed source code.

My program size is 16,384 bytes with 12,862 bytes that is used by the icon.

I think a comparable C program would be far larger.


; C_To_USB.asm Update files on thumbdrive

;

    .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\macros\macros.asm


    includelib  \masm32\lib\kernel32.lib

    includelib  \masm32\lib\user32.lib

    includelib  \masm32\lib\advapi32.lib


CTEXT MACRO y:VARARG

    LOCAL sym


    CONST segment

        IFIDNI <y>,<>

            sym db 0

        ELSE

            sym db y,0

        ENDIF

    CONST ends


    EXITM <OFFSET sym>

ENDM



IsWinNT         PROTO

ReqNTPrivilege  PROTO :DWORD


.DATA


AppName        BYTE    "C_2_USB", 0

No_Batch_File  db      "Batch file is not present.",0

Batch_File     db      "C:\Bat\J_Cruzer.bat",0


.data?


szComspec    byte    MAX_PATH dup(?)

szAppname    byte    MAX_PATH dup(?)

ProcessInfo    PROCESS_INFORMATION<?>

StartupInfo    STARTUPINFO<?>


.code

 

start:

             ; check if batch file is present

invoke GetFileAttributes,offset Batch_File


.IF EAX == 0FFFFFFFFh

   invoke MessageBox, 0, ADDR No_Batch_File, ADDR AppName,MB_ICONINFORMATION

   invoke  ExitProcess,NULL

.ENDIF


      invoke    GetStartupInfo, addr StartupInfo

    invoke    GetEnvironmentVariable, CTEXT('ComSpec'), addr szComspec, sizeof szComspec

    invoke    wsprintf, addr szAppname, CTEXT('"%s" /c "c:\Bat\J_Cruzer.bat"'), addr szComspec

    invoke    CreateProcess, 0, addr szAppname, 0, 0, FALSE, \

                NORMAL_PRIORITY_CLASS, 0, 0, addr StartupInfo, addr ProcessInfo


invoke    WaitForSingleObject, ProcessInfo.hProcess, INFINITE

        

invoke  ExitProcess,NULL


end     start


rsrc.rc


#define APP_VERSION_INFO    1     // Define at the top your .RC file 


// example version resource

APP_VERSION_INFO VERSIONINFO

    FILEVERSION 1,0         //1,1,0,0

    PRODUCTVERSION 1,0         //1,1,0,0

    FILEFLAGSMASK 0x17L

    FILEFLAGS 0x0L

    FILEOS 0x4L

    FILETYPE 0x1L

    FILESUBTYPE 0x0L

{

    BLOCK "StringFileInfo"

    {

        BLOCK "040904b0"

        {

            VALUE "CompanyName", "Siege_Works 2011"

            VALUE "FileDescription", "Files to Usb Drive"

            VALUE "FileVersion", "1.0"

            VALUE "InternalName", "C_To_Usb.exe"

            VALUE "LegalCopyright", "© QHR"

            VALUE "OriginalFilename", "C_To_Usb.exe"

        }

    }

    BLOCK "VarFileInfo"

    {

        VALUE "Translation", 0x409, 1200

    }

}


200 ICON MOVEABLE PURE LOADONCALL DISCARDABLE "Usb_Drive.ico"


Edited by dargueta, 27 January 2011 - 11:42 AM.
Dude, seriously - use code tags!


#6
mebob

mebob

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 490 posts
Well, even if an equivalent C program is longer, it is definitely easier to read. So it works fine?
Latinamne loqueris?

#7
Slider

Slider

    Learning Programmer

  • Members
  • PipPipPip
  • 33 posts
The C code is here.
Thanks mebob.

If someone could produce the program using the C code, I could study the program and it would help me a lot.

Thanks,

Andy

; Receiving Event Notification (Windows)

; Define the events in a message text file
;
; Reporting Events (Windows)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users