Results 1 to 8 of 8

Thread: Embedding Programs

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2009
    Posts
    6

    Embedding Programs

    Okay I want to create a patcher/installer type program

    I have 3 files that i need to be embedded or stored in a file
    two files need to be extracted when user clicks a button
    and one of those two files need to be run with a parameter when the button is clicked
    and last file needs to be extracted when program closes down
    All 3 files need to be able to be updated in the program

    My VB knowledge is pretty limited, so any help would be appreciated.
    Last edited by willsonfang; Dec 14th, 2009 at 09:32 AM.

  2. #2
    Hyperactive Member gonzalioz's Avatar
    Join Date
    Sep 2009
    Location
    <body></body>
    Posts
    508

    Re: Embedding Programs

    Hi Willsonfang,

    Try this:

    1. Right click on your project in the solution explorer and choose 'Add -> Existing Item'.
    You can now find your file in the solution explorer.

    2. Go to the properties window of your file and change the 'Build Action' to 'Embedded Resource'.

    3. Then add this to your code:

    Code:
                Dim embeddedResource As Stream = Reflection.Assembly.GetEntryAssembly.GetManifestResourceStream("SolutionName.Test.exe")
                Dim fileStream As New FileStream("C:\Test.exe", FileMode.OpenOrCreate)
                For index As Int64 = 0 To embeddedResource.Length - 1
                    fileStream.WriteByte(CByte(embeddedResource.ReadByte))
                Next
                fileStream.Close()
    You have to replace SolutionName with the name of your Solution, obviously and test.exe with the name of your file.

    Hope that helps!


    [EDIT]
    Almost forgot, you can start a program using Process.Start("C:\Test.exe").
    Last edited by gonzalioz; Dec 14th, 2009 at 10:56 AM.

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2009
    Posts
    6

    Re: Embedding Programs

    Quote Originally Posted by gonzalioz View Post
    Hi Willsonfang,

    Try this:

    1. Right click on your project in the solution explorer and choose 'Add -> Existing Item'.
    You can now find your file in the solution explorer.

    2. Go to the properties window of your file and change the 'Build Action' to 'Embedded Resource'.

    3. Then add this to your code:

    Code:
                Dim embeddedResource As Stream = Reflection.Assembly.GetEntryAssembly.GetManifestResourceStream("SolutionName.Test.exe")
                Dim fileStream As New FileStream("C:\Test.exe", FileMode.OpenOrCreate)
                For index As Int64 = 0 To embeddedResource.Length - 1
                    fileStream.WriteByte(CByte(embeddedResource.ReadByte))
                Next
                fileStream.Close()
    You have to replace SolutionName with the name of your Solution, obviously and test.exe with the name of your file.

    Hope that helps!
    Hmm so that embeds the file into your program, but how do you extract it?

  4. #4
    Hyperactive Member gonzalioz's Avatar
    Join Date
    Sep 2009
    Location
    <body></body>
    Posts
    508

    Re: Embedding Programs

    That's what the code does. In this case, it reads the contents (in bytes) from the embedded resource called Test.exe. Creates a new file and writes the contents of test.exe (in bytes) to C:\Test.exe.

    Test.exe can of course be anything you want.. Test.img Test.png . doc etc etc.

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2009
    Posts
    6

    Re: Embedding Programs

    Quote Originally Posted by gonzalioz View Post
    That's what the code does. In this case, it reads the contents (in bytes) from the embedded resource called Test.exe. Creates a new file and writes the contents of test.exe (in bytes) to C:\Test.exe.

    Test.exe can of course be anything you want.. Test.img Test.png etc etc.
    O sorry didn't fully read the code, thnxs alot, but it doesn't matter if its not a exe file right, i just change the "text.exe" to "Test.xxx"?

  6. #6
    Hyperactive Member gonzalioz's Avatar
    Join Date
    Sep 2009
    Location
    <body></body>
    Posts
    508

    Re: Embedding Programs

    Yep.

    I haven't figured out how to pass parameters with Process.Start yet btw .

    [EDIT]

    Got it :

    The parameters in this case is "/safe". (Starts microsoft word in safe mode)
    Code:
                Dim startInfo As New ProcessStartInfo
                startInfo.FileName = "winword.exe"
                startInfo.Arguments = "/safe"
                Process.Start(startInfo)
    Last edited by gonzalioz; Dec 14th, 2009 at 11:06 AM.

  7. #7

    Thread Starter
    New Member
    Join Date
    Dec 2009
    Posts
    6

    Re: Embedding Programs

    curious where do you find these things x.x, i tried googling and couldn't find anything about it.

  8. #8
    Hyperactive Member gonzalioz's Avatar
    Join Date
    Sep 2009
    Location
    <body></body>
    Posts
    508

    Re: Embedding Programs

    Well I knew already about Embedded Resources so I knew what I had to search for .

    I got the information from:
    http://support.microsoft.com/kb/319291
    and
    http://dotnetperls.com/process-start-examples-vbnet

    I use MSDN a lot but they always use 3million words to explain a simple piece of code lol, that's a bit irritating.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width