[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 367
  • Last Modified:

Join two exe's together???

I had a question really similar to this, but it didn't turn out very well with the answers I got, so let's try this again. :)  I have an existing EXE that I would like to join with another EXE which is a very simple GUI for the existing EXE.  The GUI is just one button on a form.  I want the button to open the existing EXE.  That's it!  But here's the trick, I want the GUI to be joined to the existing EXE.  It would be the same principal as creating an installer for a piece of software(the installer "wraps" the existing EXE).  "Process.Start" just isn't going to get it.  I have tried and tried to do this, so I need expert help.  Please provide VB.NET code.  

0
vilusion
Asked:
vilusion
  • 6
  • 2
  • 2
1 Solution
 
YZlatCommented:
Private Function StartProcess(ByVal app As String) As Process
        ' Declare the Process variable.
        Dim proc As Process

        ' Create the Process component
        proc = New Process

        ' Build the StartInfo object.
        ' Set the FileName property to the argument passed
        proc.StartInfo.FileName = app

        ' Start the Process
        proc.Start()

        Return proc
    End Function
0
 
YZlatCommented:
also you could try, where path is the path to your exe.
Another option would be using Shell command

Private Function StartProcess(ByVal app As String, ByVal path as string) As Process
        ' Declare the Process variable.
        Dim proc As Process

        ' Create the Process component
        proc = New Process

        ' Build the StartInfo object.
        ' Set the FileName property to the argument passed
        proc.StartInfo.FileName = app
      proc.StartInfo.FileName = path

        ' Start the Process
        proc.Start()

        Return proc
    End Function
0
 
vilusionAuthor Commented:
That code works great for opening up another exe but doesn't "join" two exe's together.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
vilusionAuthor Commented:
This code here works great for creating a new EXE from two EXE's but it's written in VB6 and doesn't really work too well.  It's create the new EXE but that's about it.  The upgrade wizard for VB 2005 obviously changes some things but I get an error that says "Argument 'Start' must be greater than zero".

-----------Project1 Code------------------
Private Sub Command1_Click()
    MsgBox ReadVariable("MsgBoxMessage")
End Sub

-------------Project2 Code----------------
Private Sub Command1_Click()
    AddVariable "MsgBoxMessage", Text1.Text
    WriteExeFile "project1.exe", "new.exe"
End Sub

------------Module--------------------
Option Explicit

'Declarations

Type VAREXE                                     'Variabletype used to store a variablename
                                                'and the corresponding Data.
    VarName As String
    VarData As String

End Type

Public Vars(200) As VAREXE                      'Array used to store Variablenames and Values for our new exe file
                                                'If you need more than 200 Variables you'll have to modify this line
Public Vars2(200) As VAREXE                     'Stores variablenames and data read from an exe file

Public NumberOfVarsStored As Integer            'how many variables are stored in our exe file ? (needed when reading out data from an exe file)

                                     
'#############################################################################
'
' Function: AddVariable
'
' Usage:    Add new Variables + correponding Data
'           / Modify Data of existing Variables
'
' Syntax:   AddVariable "VariableName", "VariableData"
'
' Example:  AddVariable "WindowTitle", "Example by Over. overkillpage@gmx.net"
'
'#############################################################################

Public Sub AddVariable(VarName As String, VarData As String)
   
    'Declarations
    Dim Looop As Integer                        'Variable used for any kind of loops
    Dim VarDoesAlreadyExist As Boolean          'Do we only have to change the VarData or do we have to add
                                                'a completly new Variable to the Vars Array ???
                                       
    Do                                          'In this Do-Loop we check if the Var does already exist
   
        If Vars(Looop).VarName = VarName Then   'if true it does exist !
            VarDoesAlreadyExist = True
            Exit Do
        End If
       
        Looop = Looop + 1                       'Increasing our loop variable
       
    Loop Until Vars(Looop).VarName = ""
   
    If VarDoesAlreadyExist = True Then
       
        Vars(Looop).VarData = VarData           'We only have to modify an existing Variable
   
    Else
       
        Vars(Looop).VarName = VarName           'We add a new Var + Data
        Vars(Looop).VarData = VarData
       
    End If
   
End Sub


'#############################################################################
'
' Function: WriteExeFile
'
' Usage:    Stores Variables + Data collected by AddVariable into a new exe
'           file DURING RUNTIME !
'
' Syntax:   WriteExeFile "FileNameOfAnTemplateExeFile", "NameOfNewExeFile"
'
' Example:  WriteExeFile "c:\temp.exe", "c:\new.exe"
'
'#############################################################################

Public Function WriteExeFile(TemplateExeFile As String, NameOfNewExeFile As String) As Boolean

    'Declarations
    Dim Looop As Integer                        'Variable used for any kind of loops
   
    Dim Sep1 As String * 12                     'We're gonna insert all data (vars + data) which was "collected"
    Dim Sep2 As String * 12                     'using AddVar at the end of our template file. To do so we will
    Dim Sep3 As String * 12                     'Generate one single string. Special seperators help us to split
                                                'this string into the original data when the new exe file wants
                                                'to read out the stored data.
                                                'ok guys ;) i think nobody understand this part. My English is
                                                'too bad and it's much too late.
   
    Sep1 = "|-|-sep1-|-|"                       'Ok. If you want to you can of course change these seperator strings
    Sep2 = "_-|-sep2_-|-"                       'But be carefull. Chosing strings like "a" is quite dangerous.
    Sep3 = "=-=_sep3-_=-"                       'The hole new created Exe file is searched for this seperatorstrings
                                                'and splitted accordingly. So you have to chose strings that do
                                                'NOT exist in the Temp Exe File !!
                                               

    If Dir(TemplateExeFile) = "" Then           'Checking if Template File exists, if not exiting the function
                                                'and returning an error msg
        MsgBox "Template file doesn't exist !", vbExclamation, "ERROR"
        WriteExeFile = False
        Exit Function
   
    End If

    Open TemplateExeFile For Binary Access Read As #1     'Opening the Template File.
    Open NameOfNewExeFile For Binary Access Write As #2   'opening a file to "create" a new exe file
       
                                                'Now we're gonna create the string which will be inserted at the
                                                'end of the Template Exe File
        Dim OutString As String
                                           
        OutString = Sep1                        'Inserting opening seperator
                                           
        Do                                      'Looping through all stored Variables + Data
                               
            If Vars(Looop).VarName <> "" Then   'If there is an var + data it will be added to outstring
                   
                   OutString = OutString & Vars(Looop).VarName & Sep3 & Vars(Looop).VarData & Sep2
                   
            End If
           
            Looop = Looop + 1                   'Increasing our loop variable
           
        Loop Until Vars(Looop).VarName = ""
           
        OutString = OutString & Sep1 & LOF(1)   'There are two parts in our string. one containing the vars +data
                                                'and one containing the original filelen of the tempfile. This helps
                                                'us later to read out the created string again. (When it was inserted
                                                'into the template file). Ok. The data + vars have been added so there
                                                'is another seperator followed by the filesize.
       
                                                'Finally we'll have to "create" the new exe file....
        Dim TempFile As String
        TempFile = Space$(LOF(1))
        Get #1, , TempFile                      '1. Reading out the content of the Templatefile
       
        Put #2, , TempFile & OutString          '2. Writing the Templatefile + Outstring into a new exe file !
   
    Close #1                                    'tiddy up ;)
    Close #2
   
    WriteExeFile = True                         'Everything went fine so we return True
   
End Function


'#############################################################################
'
' Function: ReadVariable
'
' Usage:    Read DURING RUNTIME a variable stored in the project's very own
'           exe file
'
' Syntax:   ReadVariable "VariableName"
'
' Example:  ReadVariable "WindowTitle"
'
'#############################################################################

Public Function ReadVariable(VarName As String) As String

    'Declarations
    Dim Looop As Integer                        'Variable used for any kind of loops
    Dim SizeOfTemplateFile                      'Will store the size of the Template File
    Dim VarString As String                     'Will hold the string of variable names and data
   
    Dim Sep1 As String * 12                     'We are using the same seperator strings we used in WriteExeFile
    Dim Sep2 As String * 12                     'Now we using to: 1. Get the OutString we added to our exe file
    Dim Sep3 As String * 12                     '2. split it into the single vars + data
                                                                                               
    Sep1 = "|-|-sep1-|-|"
    Sep2 = "_-|-sep2_-|-"
    Sep3 = "=-=_sep3-_=-"
   
    If Vars2(0).VarName = "" Then              'If NO variables are stored in the Vars2 Array we check THIS exe file
                                                'for stored Vars + Data ! Else we only return the stored Data.
   
       
        Open App.EXEName & ".exe" For Binary Access Read As #3     'Funny ;) isn't it ? But this is THE trick of this sourcecode ;)
                                                            'we open the exe file of this program !! and read out data from
                                                            'the end of the file !
                                                            'For German users ;): "Der Moment wo der Elefant das Wasser läßt ;)"
        Dim EXEString As String
        EXEString = Space$(LOF(3))
        Get #3, , EXEString                                 'Reading out the content of the exe file of THIS Project
       
        Looop = LOF(3) - Len(Sep3)                          'We start reading out the content beginning at the end of the file
       
        Do                                                  'We stored the len of the template file at the end, before this there
                                                            'is a sep1. So we search it :)
           Looop = Looop - 1
           Dim egal
       
        Loop Until Mid(EXEString, Looop, Len(Sep3)) = Sep1
           
        SizeOfTemplateFile = Mid(EXEString, Looop + Len(Sep1))      'Read out the filelen of the templatefile
        VarString = Mid(EXEString, SizeOfTemplateFile + 1)          'Now we read out the Var + Data String
        VarString = Left(VarString, Looop - SizeOfTemplateFile - 1) 'Cutting of end seperator
        VarString = Mid(VarString, Len(Sep1) + 1)                   'We cut of the initialition seperator
        VarString = Left(VarString, Len(VarString) - Len(Sep2))     'cutting of the sep2 at the end
   
        For Looop = 1 To Len(VarString)                             'Count number of Variables stored in VarString
           
            If Mid(VarString, Looop, Len(Sep2)) = Sep2 Then NumberOfVarsStored = NumberOfVarsStored + 1
       
        Next Looop
       
        For Looop = 0 To NumberOfVarsStored                         'storing vars + data in the vars2 array
               
            Vars2(Looop).VarName = Split((Split(VarString, Sep2)(Looop)), Sep3)(0)
            Vars2(Looop).VarData = Split((Split(VarString, Sep2)(Looop)), Sep3)(1)
       
        Next Looop
           
        Close #3
       
   
   
    End If
   
    'Reading out data for the requested variablename
    For Looop = 0 To NumberOfVarsStored                         'storing vars + data in the vars2 array
           
        If UCase(Vars2(Looop).VarName) = UCase(VarName) Then    'We use ucase to make the check not case sensitive
            ReadVariable = Vars2(Looop).VarData                 'Returning requested data
            Exit For
        End If
   
    Next Looop
   
End Function
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
vilusion,

The code you have posted does NOT create a new EXE from two EXEs.

It allows you to add variables to the end of an EXE which can be read back later.

Even if you took one EXE, read it all into a string, and appended it to the end of another...that won't make it so that you can run both EXEs from the same executable.  It would just be a bunch of data hanging off the end of the original EXE file.

As far as I know, there is NO way to take data from a file, load it into memory, and then run that code directly from memory as if it were an EXE launched from the hard drive.

I think the closest you could get would be to concatenate the two together, extract the second EXE to a temp EXE, and then run that temp EXE.

Probably not what you want to hear but there it is...

~IM
0
 
vilusionAuthor Commented:
Idle_Mind,

Thank you for looking over that code.  It does create a new EXE but when executed it runs "Project1.exe".  I understand what you're saying.

 "As far as I know, there is NO way to take data from a file, load it into memory, and then run that code directly from memory as if it were an EXE launched from the hard drive.

I think the closest you could get would be to concatenate the two together, extract the second EXE to a temp EXE, and then run that temp EXE."


Question: Then how do you wrap an EXE like an installer does or when you make a trial version of your software?

Thanks!
0
 
vilusionAuthor Commented:
Without using a third party installer.
0
 
vilusionAuthor Commented:
Or do you have anything that would do the same thing pretty much like the code above, except for VB.NET?  Sorry for all of the questions, I'm just trying to undertand this because I wish to be able to add a GUI to any EXE, like a "wrapper" does.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
The code makes a new EXE by appending "variables" to an existing EXE.

Even if the code could append one EXE to another, it would not produce a new EXE where both the original EXE and the appended EXE could be run together from the same file.



An INSTALLER extracts the embedded EXE to it's own file on the hard drive so you can run it by itself afterwards WITHOUT the original installer executable.

Most "wrappers" do the something similar but usually encrypt the exe so it can't be run by itself (which isn't a very good approach) or use some variation of an encrypted/hidden external file that the EXE checks certain conditions for.  Or it uses some kind of webservice to authenticate it's users each time to verify if they have the proper rights to run the file.

Also, many wrappers are actually included in the SOURCE code of the EXE as a component, and then compiled into the EXE.  In this sense, it is NOT one EXE wrapping another.  It is a component or DLL being used/called from an EXE.

It may be possible to edit an EXE in such a way that you can do what you request, but I don't personally know enough about the PE format to accomplish this myself:
http://www.windowsitlibrary.com/Content/356/11/1.html
0
 
vilusionAuthor Commented:
Thank you, you got me a lot closer!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 6
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now