|
-
Jul 5th, 2003, 11:54 AM
#1
Thread Starter
New Member
Embedded Resource
Hi!
I have embedded an .exe file in my project... How can I in the most easy way save this file on the HD?
Thanks /Ale
-
Jul 8th, 2003, 03:10 AM
#2
Use the Assembly
Hi.
You can use the reflection.assembly for this.
Code:
Dim A As Reflection.Assembly = reflection.Assembly.GetExecutingAssembly
Dim ST As IO.Stream = A.GetManifestResourceStream("AppName.OrginalFilename.Exe")
Dim B(ST.Length - 1) As Byte
ST.Read(B, 0, B.Length)
Dim ST2 As IO.Stream = IO.File.OpenWrite("NewFileName.exe")
ST2.Write(B, 0, B.Length)
ST.Close()
ST2.Close()
I hope this help.
Cheers
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Jul 14th, 2003, 07:38 AM
#3
Thread Starter
New Member
Hi, really thanks for your help... But I can't get it to work...
Dim B(ST.Length - 1) As Byte
This line says something like: objectreferense has not been choosen to an instance of an object
What to do, any ideas?
/Ale
-
Jul 14th, 2003, 09:06 AM
#4
Sleep mode
Make sure you type the correct file name !
-
Jul 14th, 2003, 11:06 AM
#5
Fanatic Member
How were you able to embed the exe file? Can you share some code?
-
Jul 15th, 2003, 04:29 AM
#6
Thread Starter
New Member
I'm really sure I have the right filename, it doesn't work anyway...
How to embedd your exe: Right click your project in the solution window, then add existing item, choose all files and select your exe... The change from "compile" to "embedded resoure" in the properties window... Hopes this helps...
/Ale
-
Jul 15th, 2003, 08:17 AM
#7
Sleep mode
Can you show us how you tried the above code ?
-
Sep 1st, 2003, 03:00 PM
#8
Hyperactive Member
I have the same problem with your code,
I have just put this code behind a button:
Code:
Dim A As Reflection.Assembly = reflection.Assembly.GetExecutingAssembly
Dim ST As IO.Stream = A.GetManifestResourceStream("AppName.OrginalFilename.Exe")
Dim B(ST.Length - 1) As Byte
ST.Read(B, 0, B.Length)
Dim ST2 As IO.Stream = IO.File.OpenWrite("NewFileName.exe")
ST2.Write(B, 0, B.Length)
ST.Close()
ST2.Close()
and this is the error message:
Code:
An unhandled exception of type 'System.NullReferenceException' occurred in ModelInstaller.exe
-
Sep 1st, 2003, 05:35 PM
#9
the embedded file must be spot on when trying to read it, this is a quick sample which works fine with an embedded file...
VB Code:
[COLOR=BLUE]Private[/COLOR] [COLOR=BLUE]Sub[/COLOR] Button1_Click([COLOR=BLUE]ByVal[/COLOR] sender [COLOR=BLUE]As[/COLOR] System.Object, [COLOR=BLUE]ByVal[/COLOR] e [COLOR=BLUE]As[/COLOR] System.EventArgs) [COLOR=BLUE]Handles[/COLOR] Button1.Click
[COLOR=BLUE]Dim[/COLOR] path [COLOR=BLUE]As[/COLOR] [COLOR=BLUE]String[/COLOR] = Application.ProductName & ".closing forms.exe" [COLOR=GREEN]'/// must be the exact path of the embedded exe.
[/COLOR] [COLOR=BLUE]Dim[/COLOR] sReader [COLOR=BLUE]As[/COLOR] [COLOR=BLUE]New[/COLOR] IO.StreamReader([COLOR=BLUE]MyBase[/COLOR].GetType.Assembly.GetManifestResourceStream(path))
[COLOR=BLUE]Dim[/COLOR] sWriter [COLOR=BLUE]As[/COLOR] [COLOR=BLUE]New[/COLOR] IO.StreamWriter([COLOR=BLUE]New[/COLOR] IO.FileStream("D:\closing_forms.exe", IO.FileMode.OpenOrCreate))
[COLOR=BLUE]While[/COLOR] [COLOR=BLUE]Not[/COLOR] sReader.Peek
sWriter.WriteLine(sReader.ReadLine)
[COLOR=BLUE]End[/COLOR] [COLOR=BLUE]While
[/COLOR] sWriter.Close()
sReader.Close()
[COLOR=BLUE]End[/COLOR] [COLOR=BLUE]Sub[/COLOR]
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Sep 2nd, 2003, 01:03 PM
#10
Hyperactive Member
yeah, BUT I want it to save the file to the Hard Drive says for your example's sake:
C:\test.txt
Thank you,
-
Sep 2nd, 2003, 02:34 PM
#11
yeah, BUT I want it to save the file to the Hard Drive says for your example's sake:
C:\test.txt
this line saves the file to the specified hard disk path....
VB Code:
[color=blue]Dim[/color] sWriter [color=blue]As New[/color] IO.StreamWriter(New IO.FileStream("D:\closing_forms.exe", IO.FileMode.OpenOrCreate))
where D:\ is the hard drive path i'm saving the .exe " closing_forms.exe" to.
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Sep 3rd, 2003, 11:18 AM
#12
Hyperactive Member
I'm getting an error with your code too,
this line
Code:
sReader As New IO.StreamReader(MyBase.GetType.Assembly.GetManifestResourceStream(path))
produces an error says that it can not be Null,
here is my Code:
Code:
Private Sub cmd_Install_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_Install.Click
Dim path As String = Application.ProductName & ".exe text.txt" '/// must be the exact path of the embedded exe.
MessageBox.Show(path)
Dim sReader As New IO.StreamReader(MyBase.GetType.Assembly.GetManifestResourceStream(path))
Dim sWriter As New IO.StreamWriter(New IO.FileStream("C:\test.txt", IO.FileMode.OpenOrCreate))
While Not sReader.Peek
sWriter.WriteLine(sReader.ReadLine)
End While
sWriter.Close()
sReader.Close()
End Sub
can you help point out where I am going wrong?
thank you
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
|