|
-
Dec 14th, 2009, 09:25 AM
#1
Thread Starter
New Member
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.
-
Dec 14th, 2009, 10:49 AM
#2
Hyperactive Member
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.
-
Dec 14th, 2009, 10:55 AM
#3
Thread Starter
New Member
Re: Embedding Programs
 Originally Posted by gonzalioz
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?
-
Dec 14th, 2009, 10:58 AM
#4
Hyperactive Member
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.
-
Dec 14th, 2009, 10:59 AM
#5
Thread Starter
New Member
Re: Embedding Programs
 Originally Posted by gonzalioz
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"?
-
Dec 14th, 2009, 11:01 AM
#6
Hyperactive Member
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.
-
Dec 14th, 2009, 11:08 AM
#7
Thread Starter
New Member
Re: Embedding Programs
curious where do you find these things x.x, i tried googling and couldn't find anything about it.
-
Dec 14th, 2009, 11:13 AM
#8
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|