Attention Mcrider

Mr. mcrider-->I just read your code concerning "necco" having to do with extracting an executable file from another executable file. Here is your original code:
Public Const INFINITE = -1&

                    Private Declare Function OpenProcess Lib "kernel32" (ByVal _
                        dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
                        ByVal dwProcessID As Long) As Long

                   Private Type STARTUPINFO
                      cb As Long
                      lpReserved As String
                      lpDesktop As String
                      lpTitle As String
                      dwX As Long
                      dwY As Long
                      dwXSize As Long
                      dwYSize As Long
                      dwXCountChars As Long
                      dwYCountChars As Long
                      dwFillAttribute As Long
                      dwFlags As Long
                      wShowWindow As Integer
                      cbReserved2 As Integer
                      lpReserved2 As Long
                      hStdInput As Long
                      hStdOutput As Long
                      hStdError As Long
                   End Type

                   Private Type PROCESS_INFORMATION
                      hProcess As Long
                      hThread As Long
                      dwProcessID As Long
                      dwThreadID As Long
                   End Type

                   Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
                      hHandle As Long, ByVal dwMilliseconds As Long) As Long

                   Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
                      lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
                      lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
                      ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
                      ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
                      lpStartupInfo As STARTUPINFO, lpProcessInformation As _
                      PROCESS_INFORMATION) As Long

                   Private Declare Function CloseHandle Lib "kernel32" _
                      (ByVal hObject As Long) As Long

                   Private Declare Function GetExitCodeProcess Lib "kernel32" _
                      (ByVal hProcess As Long, lpExitCode As Long) As Long

                   Private Const NORMAL_PRIORITY_CLASS = &H20&
                   Public Function ExecCmd(cmdline$)
                      Dim proc As PROCESS_INFORMATION
                      Dim start As STARTUPINFO

                      ' Initialize the STARTUPINFO structure:
                      start.cb = Len(start)

                      ' Start the shelled application:
                      ret& = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
                         NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)


                      ' Wait for the shelled application to finish:
                         ret& = WaitForSingleObject(proc.hProcess, INFINITE)
                         Call GetExitCodeProcess(proc.hProcess, ret&)
                         Call CloseHandle(proc.hThread)
                         Call CloseHandle(proc.hProcess)
                         ExecCmd = ret&
                    End Function
                     
My question is can you attach a compressed executable file in the same manner ie somefile.ex_ and then have this file placed into a C:\whatever directory ? You know, like "piggyback" this file ? This is really cool, I hope it can be done. Ain't too smart either but i would like to know how. Maybe you could modify your code above to show how this could be done ?

Thanks, you got my vote !
gbfine
gbfineAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mcriderCommented:
Yes, the file you attach can be ANY EXE... It could be for example, a WINZIP selfextracting zip file containing 30 files... When the EXE is detached from your program using my code, it would run the selfextracting zip EXE and explode out the 30 files...


Cheers!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mcriderCommented:
As for microsoft compressed files, after you close the files in that code, you can do this you can use the ExecCmd call to wait for the uncompress the file to complete, then use the ExecCmd to run the program...


Something like:

ExecCmd "expand " + TempFile + " temprun.exe"
ExecCmd "temprun.exe"


Cheers!
0
gbfineAuthor Commented:
mcrider--->How do i change the code above to place the "piggyback" file into the C:\whatever directory ? Other than that, i have it figured out !
Thanks Alot
gbfine
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

mcriderCommented:
Ok, here is completely modified code... This will detach the compressed .EX_ file, expand it, and then copy the EXE to wherever you want it to go, and delete the temp .EX_ and temp .EXE files....


Put this code in a MODULE:

    Public Const INFINITE = -1&

    Private Declare Function OpenProcess Lib "kernel32" (ByVal _
        dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
        ByVal dwProcessID As Long) As Long

   Private Type STARTUPINFO
      cb As Long
      lpReserved As String
      lpDesktop As String
      lpTitle As String
      dwX As Long
      dwY As Long
      dwXSize As Long
      dwYSize As Long
      dwXCountChars As Long
      dwYCountChars As Long
      dwFillAttribute As Long
      dwFlags As Long
      wShowWindow As Integer
      cbReserved2 As Integer
      lpReserved2 As Long
      hStdInput As Long
      hStdOutput As Long
      hStdError As Long
   End Type

   Private Type PROCESS_INFORMATION
      hProcess As Long
      hThread As Long
      dwProcessID As Long
      dwThreadID As Long
   End Type

   Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
      hHandle As Long, ByVal dwMilliseconds As Long) As Long

   Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
      lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
      lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
      ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
      ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
      lpStartupInfo As STARTUPINFO, lpProcessInformation As _
      PROCESS_INFORMATION) As Long

   Private Declare Function CloseHandle Lib "kernel32" _
      (ByVal hObject As Long) As Long

   Private Declare Function GetExitCodeProcess Lib "kernel32" _
      (ByVal hProcess As Long, lpExitCode As Long) As Long

   Private Const NORMAL_PRIORITY_CLASS = &H20&
   Public Function ExecCmd(cmdline$)
      Dim proc As PROCESS_INFORMATION
      Dim start As STARTUPINFO

      ' Initialize the STARTUPINFO structure:
      start.cb = Len(start)

      ' Start the shelled application:
      ret& = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
         NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)


      ' Wait for the shelled application to finish:
         ret& = WaitForSingleObject(proc.hProcess, INFINITE)
         Call GetExitCodeProcess(proc.hProcess, ret&)
         Call CloseHandle(proc.hThread)
         Call CloseHandle(proc.hProcess)
         ExecCmd = ret&
    End Function
     



Then put this code in the commandbutton:


    Private Sub Command1_Click()
        'THIS CONSTANT MUST BE CHANGE TO THE SIZE
        'OF THE ATTACHED EXE IN BYTES
        Const AttachedExeSize = 8704
         
        Dim TempFnum As Long
        Dim TempEx_ As String
        Dim TempExe As String
        Dim MySelfFnum As Long
        Dim MySelfExe As String
        Dim MySelfSize As Long
        Dim lByte As Byte
         
        'BUILD THE PATH TO MYSELF
        MySelfExe = App.Path
        If Not Right$(MySelfExe, 1) = "\" Then MySelfExe = MySelfExe + "\"
        MySelfExe = MySelfExe + App.EXEName + ".EXE"
         
        'GET A FREE FILENUMBER TO OPEN MYSELF AND OPEN MYSELF
        MySelfFnum = FreeFile
        Open MySelfExe For Binary Access Read As MySelfFnum
       
       
        'FIND THE START OF THE SECOND EXE
        MySelfSize = LOF(MySelfFnum)
        Seek MySelfFnum, MySelfSize - AttachedExeSize + 1
         
        'BUILD THE PATH TO THE TEMP FILE .EX_ and .EXE
        TempEx_ = Environ("TEMP")
        If Not Right$(TempEx_, 1) = "\" Then TempEx_ = TempEx_ + "\"
        TempEx_ = TempEx_ + "TMP" + Format(Now, "hhnnss") + ".EX_"
        TempExe = TempEx_
        Mid$(TempExe, Len(TempExe), 1) = "E"
       
         
        'GET A FREE FILENUMBER TO THE TEMP FILE AND OPEN IT
        TempFnum = FreeFile
        Open TempEx_ For Binary Access Write As TempFnum
         
        'EXTRACT THE FILE
        Do
            Get #MySelfFnum, , lByte
            If EOF(MySelfFnum) = True Then Exit Do
            Put #TempFnum, , lByte
        Loop
         
        'CLOSE THE FILES
        Close MySelfFnum
        Close TempFnum
         
        'EXPAND THE EXTRACTED EX_ FILE
        ExecCmd "expand " + TempEx_ + " " + TempExe

        'REPLACE THE "C:\whatever directory" WITH THE REAL PATH
        FileCopy TempExe, "C:\whatever directory"
         
        'DELETE THE EXTRACTED EX_ AND EXE
        Kill TempEx_
        Kill TempExe
    End Sub



Dont forget to change the constant AttachedExeSize and add the path to where you want the file installed in the FileCopy line...



Cheers!

0
gbfineAuthor Commented:
howdy mcrider--->I figured this out and then came here to give you your points. You did it the way i did. I must be getting LUCKY !
Thanks:)you da man !
gbfine
0
mcriderCommented:
Thanks for the points! Glad I could help!


Cheers!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.