Link to home
Start Free TrialLog in
Avatar of vilusion
vilusion

asked on

Open one EXE before another....

I'm programming an interface to add to any EXE.  The problem is, is that I don't know how to do this really.  I guess you can call this an EXE wrapper?  Here is the process.

1.  Open existing EXE
2.  Modify the EXE so that the interface that I'm programming displays first
3.  Re-save the modified EXE

Here is the code I have so far.  Not much code, but it really isn't a difficult one:


Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click

        OpenFile.Filter = "Executable Files (*.exe) | *.exe"
        OpenFile.ShowDialog()
        txtFileName.Text = System.IO.Path.GetFileName(OpenFile.FileName)

End Sub

Private Sub btnAddInterface_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddInterface.Click
         <---------- What do I put here?-------------->
End Sub
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

That is not enough of a description to offer any concrete advice, in my opinion.

Bob
Avatar of vilusion
vilusion

ASKER

Can you add two EXE's together in that the first will open, then the user clicks a button and the second opens.  I'm not sure else on how to explain this.
ASKER CERTIFIED SOLUTION
Avatar of armoghan
armoghan
Flag of Pakistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The tricky thing about Process.Start, though, is that it can't tell you when the process actually started, only when it was closed.

Bob
I think the best way to explain this, is to compare this to an EXE wrapper that creates a trial version of your software.  Even though, that's not what I'm doing, but the principal and the process appears to be the same.  So yes armoghan you are correct in that I wish to open my GUI first and the user decides when to run the EXE application.  I can't find any VB.NET code in EE but I found some EXE wrapper code written in VB6 in PlanetSourceCode but it is too difficult to understand, in my opinion.  Here is the link if you're interested.  

http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=49120&lngWId=1
I would assume you have to open the EXE in binary access, except I don't know how to do that.
>>The tricky thing about Process.Start, though, is that it can't tell you when the process actually >>started, only when it was closed.
Bob
What do you mean by that?. Process.Start works asyncronously.. so as soon as you start the prcess you can get the time of its start
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I found some code, can't remember where, that I think will take me closer to what I'm looking for.  The example has two EXE's.  The first "project" is just one Form with One cmdButton and the second "project" has one Form with a txtBox and one cmdButton.  When you open the second EXE and type something in the txtBox, then click the cmdButton, it saves a Third EXE.  When you execute the Third EXE it is the "First EXE"(first project.  with only one cmdButton), and when you click the cmdButton it displays the text you just wrote.  VERY NICE I must say!  Here is the code for future reference for everyone.

------------Code in Project1-------------

Private Sub Command1_Click()
    MsgBox ReadVariable("MsgBoxMessage")
End Sub

------------Code in Project2-------------

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

--------------Module--------------------

Option Strict Off
Option Explicit On
Module WriteToReadFromExe
      
      'Declarations
      
      Structure VAREXE 'Variabletype used to store a variablename
            'and the corresponding Data.
            Dim VarName As String
            Dim VarData As String
      End Structure
      
      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 Short '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(ByRef VarName As String, ByRef VarData As String)
            
            'Declarations
            Dim Looop As Short '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(ByRef TemplateExeFile As String, ByRef NameOfNewExeFile As String) As Boolean
            
            'Declarations
            Dim Looop As Short 'Variable used for any kind of loops
            
            Dim Sep1 As New VB6.FixedLengthString(12) 'We're gonna insert all data (vars + data) which was "collected"
            Dim Sep2 As New VB6.FixedLengthString(12) 'using AddVar at the end of our template file. To do so we will
            Dim Sep3 As New VB6.FixedLengthString(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.Value = "|-|-sep1-|-|" 'Ok. If you want to you can of course change these seperator strings
            Sep2.Value = "_-|-sep2_-|-" 'But be carefull. Chosing strings like "a" is quite dangerous.
            Sep3.Value = "=-=_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 !!
            
            
            'UPGRADE_WARNING: Dir has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
            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 !", MsgBoxStyle.Exclamation, "ERROR")
                  WriteExeFile = False
                  Exit Function
                  
            End If
            
            FileOpen(1, TemplateExeFile, OpenMode.Binary, OpenAccess.Read) 'Opening the Template File.
            FileOpen(2, NameOfNewExeFile, OpenMode.Binary, OpenAccess.Write) '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.Value '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.Value & Vars(Looop).VarData & Sep2.Value
                        
                  End If
                  
                  Looop = Looop + 1 'Increasing our loop variable
                  
            Loop Until Vars(Looop).VarName = ""
            
            OutString = OutString & Sep1.Value & 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))
            'UPGRADE_WARNING: Get was upgraded to FileGet and has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
            FileGet(1, TempFile) '1. Reading out the content of the Templatefile
            
            'UPGRADE_WARNING: Put was upgraded to FilePut and has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
            FilePut(2, TempFile & OutString) '2. Writing the Templatefile + Outstring into a new exe file !
            
            FileClose(1) 'tiddy up ;)
            FileClose(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(ByRef VarName As String) As String
            
            'Declarations
            Dim Looop As Short 'Variable used for any kind of loops
            Dim SizeOfTemplateFile As Object 'Will store the size of the Template File
            Dim VarString As String 'Will hold the string of variable names and data
            
            Dim Sep1 As New VB6.FixedLengthString(12) 'We are using the same seperator strings we used in WriteExeFile
            Dim Sep2 As New VB6.FixedLengthString(12) 'Now we using to: 1. Get the OutString we added to our exe file
            Dim Sep3 As New VB6.FixedLengthString(12) '2. split it into the single vars + data
            
            Sep1.Value = "|-|-sep1-|-|"
            Sep2.Value = "_-|-sep2_-|-"
            Sep3.Value = "=-=_sep3-_=-"
            
            Dim EXEString As String
            Dim egal As Object
            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.
                  
                  
                  'UPGRADE_WARNING: App property App.EXEName has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
                  FileOpen(3, My.Application.Info.AssemblyName & ".exe", OpenMode.Binary, OpenAccess.Read) '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 ;)"
                  EXEString = Space(LOF(3))
                  'UPGRADE_WARNING: Get was upgraded to FileGet and has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
                  FileGet(3, EXEString) 'Reading out the content of the exe file of THIS Project
                  
                  Looop = LOF(3) - Len(Sep3.Value) '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
                        
                  Loop Until Mid(EXEString, Looop, Len(Sep3.Value)) = Sep1.Value
                  
                  'UPGRADE_WARNING: Couldn't resolve default property of object SizeOfTemplateFile. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
                  SizeOfTemplateFile = Mid(EXEString, Looop + Len(Sep1.Value)) 'Read out the filelen of the templatefile
                  'UPGRADE_WARNING: Couldn't resolve default property of object SizeOfTemplateFile. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
                  VarString = Mid(EXEString, SizeOfTemplateFile + 1) 'Now we read out the Var + Data String
                  'UPGRADE_WARNING: Couldn't resolve default property of object SizeOfTemplateFile. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
                  VarString = Left(VarString, Looop - SizeOfTemplateFile - 1) 'Cutting of end seperator
                  VarString = Mid(VarString, Len(Sep1.Value) + 1) 'We cut of the initialition seperator
                  VarString = Left(VarString, Len(VarString) - Len(Sep2.Value)) '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.Value)) = Sep2.Value 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.Value)(Looop), Sep3.Value)(0)
                        Vars2(Looop).VarData = Split(Split(VarString, Sep2.Value)(Looop), Sep3.Value)(1)
                        
                  Next Looop
                  
                  FileClose(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
End Module
-------------------------------------------------------------------------------------
Thanks for your effort.  I split the points.