Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Open one EXE before another....

Posted on 2006-05-08
10
Medium Priority
?
238 Views
Last Modified: 2010-08-05
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
0
Comment
Question by:vilusion
  • 5
  • 3
  • 2
10 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16635818
That is not enough of a description to offer any concrete advice, in my opinion.

Bob
0
 

Author Comment

by:vilusion
ID: 16635869
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.
0
 
LVL 18

Accepted Solution

by:
armoghan earned 750 total points
ID: 16637124
Hi vilusion,
> Private Sub btnAddInterface_Click(ByVal sender As System.Object, ByVal
> e As System.EventArgs) Handles btnAddInterface.Click
>          <---------- What do I put here?-------------->
What I have comprehended is that you want to run an EXE, but before running that EXE you want to show a Splash Screen or say show Some GUI.

So the way would be

Private Sub btnAddInterface_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddInterface.Click
' Here Show your GUI or interface
' After that has been completed.
 Process.Start( txtFileName.Text ) ' This line runs the selected EXE from OpenFile Dialog
End Sub


Cheers!
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 96

Expert Comment

by:Bob Learned
ID: 16638614
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
0
 

Author Comment

by:vilusion
ID: 16640328
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
0
 

Author Comment

by:vilusion
ID: 16645401
I would assume you have to open the EXE in binary access, except I don't know how to do that.
0
 
LVL 18

Expert Comment

by:armoghan
ID: 16645555
>>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
0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 750 total points
ID: 16647618
Yes, you can tell when the process first starts.  But what if the application takes a few seconds to start.  Can you tell when the application actually started?  No.

Bob
0
 

Author Comment

by:vilusion
ID: 16648942
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
-------------------------------------------------------------------------------------
0
 

Author Comment

by:vilusion
ID: 16651129
Thanks for your effort.  I split the points.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Loops Section Overview
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question