Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Variation on executable file execute.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Variation on executable file execute.

    This is the test piece for a number of functions, 2 variants of execute EXE file, 1 with a basic string, the other with a zero terminated string address and an asynchronous "CreateProcess" function call. The two execute functions have the additional code to test if the file exists so that you have slightly more useful information returned if the exec function does not work. If you want a simpler approach, you have the old WinExec() function that is just a wrapper to CreateProcess.
    Code:
    ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    
        #compile exe "exec.exe"
    
        #include "\basic\include\win32api.inc"
    
    ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    
     FUNCTION PBmain as LONG
    
        cmd$ = command$
    
        If exec(cmd$) = 0 Then
          MessageBox 0, "File Not Found", "Error",%MB_OK
        End If
    
     End FUNCTION
    
    ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    
     DECLARE FUNCTION Find_First_File LIB "KERNEL32.DLL" ALIAS "FindFirstFileA" _
                     (ByVal lpFileName AS DWORD, lpFindFileData AS WIN32_FIND_DATA) AS DWORD
    
     FUNCTION exec(basic$) as DWORD
    
        LOCAL pst as DWORD
        LOCAL wfd as WIN32_FIND_DATA
        LOCAL rvl as DWORD
    
        pst = StrPtr(basic$)
    
        rvl = Find_First_File(pst,ByVal VarPtr(wfd))
    
        If rvl = %INVALID_HANDLE_VALUE Then
          FUNCTION = 0                              ' 0 = file not found
          Exit FUNCTION
        Else
          FindClose rvl
          FUNCTION = run_asynchronous(pst)          ' run file
        End If
    
    End FUNCTION
    
    ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    
     DECLARE FUNCTION Find_First_File LIB "KERNEL32.DLL" ALIAS "FindFirstFileA" _
                     (ByVal lpFileName AS DWORD, lpFindFileData AS WIN32_FIND_DATA) AS DWORD
    
     FUNCTION szexec(ByVal lpszFileName as DWORD) as DWORD
    
        LOCAL wfd as WIN32_FIND_DATA
        LOCAL rvl as DWORD
    
        rvl = Find_First_File(lpszFileName,ByVal VarPtr(wfd))
    
        If rvl = %INVALID_HANDLE_VALUE Then
          FUNCTION = 0                              ' 0 = file not found
          Exit FUNCTION
        Else
          FindClose rvl
          FUNCTION = run_asynchronous(lpszFileName) ' run file
        End If
    
    End FUNCTION
    
    ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    
     DECLARE FUNCTION Create_Process LIB "KERNEL32.DLL" ALIAS "CreateProcessA"( _
             ByVal DWORD,ByVal DWORD,ByVal DWORD,ByVal DWORD,ByVal DWORD, _
             ByVal DWORD,ByVal DWORD,ByVal DWORD,ByVal DWORD,ByVal DWORD) as DWORD
    
     FUNCTION run_asynchronous(ByVal lpfilename as DWORD) as DWORD
    
        LOCAL st_info as STARTUPINFO
        LOCAL pr_info as PROCESS_INFORMATION
        LOCAL rval as DWORD
    
        rval = Create_Process(0,lpfilename, _
                              0,0,0,0,0,0, _
                              VarPtr(st_info), _
                              VarPtr(pr_info))
    
        CloseHandle pr_info.hThread
        CloseHandle pr_info.hProcess
    
        FUNCTION = rval
    
     End FUNCTION
    
    ' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    hutch at movsd dot com
    The MASM Forum

    www.masm32.com
Working...
X