is there a way to write everything embedded to a tempfolder not just dlls , everything in resources and assign a process to a button from there ?
Printable View
is there a way to write everything embedded to a tempfolder not just dlls , everything in resources and assign a process to a button from there ?
Take a look at this.
This is more or less what im trying to accomplish.
http://www.megaupload.com/?d=X734SNDQ
My question is now how can i get all the files dlls texts project files and compile it into one single exe that wont require installation just execute my form and run it and how can i stop what happens on the video which when i open the embedded program it copy itself to the drive and stay there after i close it cause i dont mind putting aall dlls in project folder but when i gi e my exe to someone is just one file executable and with working embedded program
I'm not downloading files that contain executables. Did you read the thread? The first reply is exactly what you have to do. Google is your best bet. This is the second result of Googling "embedding dlls vb.net".
What about stopping the exe from writing itself to the drive? Ill post another video with the app in the link so u know what i mean and yeah i read it but how can i set it up and what i want to do is fuze everything not just dlls to my main form
You can embed literally any type of file into your .exe. It is not limited to dlls. I don't understand what this means:
Writing itself...? Are you talking about when it writes the dll out? You might be able to write it into memory and then read it. But if you do it as a temp file in the temp folder, the user won't know.Quote:
What about stopping the exe from writing itself to the drive?
When you write the embedded resource to disk, you need to hold on to the file path where it is written to (store it in a global or shared variable that can be accessed elsewhere). You then handle the application.shutdown event and delete the file there.
Yeah as u see in the video in my folder i delete the exe the open my form press button to execute the embedded form and it works fine but when i close my form
It stay there and i need to delete again wyat would be the steps to write it to a temp folder or path that would be deleted when i close my form since the point is the user cant use the software if hes not using my form
If you’re true intent is to simply give a user one executable assuming the correct .NET Framework is installed then why not simply embed the DLL/assembly as an embedded resource and allow .NET to load the DLL/assembly if it is missing. Why hide this file if you have the rights to use it?
The attached solution has two projects. The first project is a simple class library with a single class Customer. The second Windows form project references the class library and creates a list of customers, which are displayed in a DataGridView.
If the class library DLL is not located when your application requires it the following code will extract the DLL from the primary assembly and load it.
To test it out, build the solution then remove the DLL from the Windows form project directory followed by running the Windows form executable. The DLL will be extracted from the code in ResolveEventHandler. Of course instead of the logic in ResolveEventHandler you could find other methods but I think this works well.
Hook into AssemblyResolve, find the customer dll and load it.
Support Name of the DLL which is embeddedCode:Public Sub New()
InitializeComponent()
AddHandler AppDomain.CurrentDomain.AssemblyResolve, AddressOf ResolveEventHandler
End Sub
Function ResolveEventHandler(ByVal sender As Object, ByVal args As ResolveEventArgs) As Assembly
Dim ExecutingAssemblies As Assembly = Assembly.GetExecutingAssembly()
Dim ReferencedAssmbNames() As AssemblyName = ExecutingAssemblies.GetReferencedAssemblies()
Dim AssemblyName As AssemblyName
Dim MyAssembly As Assembly = Nothing
For Each AssemblyName In ReferencedAssmbNames
'Look for the assembly names that have raised the "AssemblyResolve" event.
If (AssemblyName.FullName.Substring(0, AssemblyName.FullName.IndexOf(",")) = args.Name.Substring(0, args.Name.IndexOf(","))) Then
Dim TempAssemblyPath As String
TempAssemblyPath = IO.Path.Combine(Application.StartupPath, args.Name.Substring(0, args.Name.IndexOf(",")) & ".dll")
My.Resources.CustomerDemo.FileSave(My.Application.CustomerDllFileName)
Application.DoEvents()
'Load the assembly from the specified path.
MyAssembly = Assembly.LoadFrom(TempAssemblyPath)
Exit For
End If
Next
Return MyAssembly
End Function
Used to extract embedded DLLCode:Namespace My
Partial Friend Class MyApplication
Public ReadOnly Property CustomerDllFileName() As String
Get
Return IO.Path.Combine(My.Application.Info.DirectoryPath, "CustomerDemo.dll")
End Get
End Property
End Class
End Namespace
ReferencesCode:<System.Runtime.CompilerServices.Extension()> _
Public Sub FileSave(ByVal BytesToWrite() As Byte, ByVal FileName As String)
If IO.File.Exists(FileName) Then
IO.File.Delete(FileName)
End If
Dim FileStream As New System.IO.FileStream(FileName, System.IO.FileMode.OpenOrCreate)
Dim BinaryWriter As New System.IO.BinaryWriter(FileStream)
BinaryWriter.Write(BytesToWrite)
BinaryWriter.Close()
FileStream.Close()
End Sub
ResolveEventHandler Delegate
Unload Assemblies From an Application Domain
o couldnt open it in visual basic 2010 , ok a few questions namespace my what si supposed to go there
this is my project of u can download it and put that code in there so i can see how it works i appreciated it, the site wont let me upload more than 500kb
http://www.megaupload.com/?d=C1MRXQN4
im uploading a video know when i finish u see what i need
ok managed to open it how can i use this ??? what would be the codes to use and how i can create all those things that i dont have like mynamespace.vb and such
this is my problem and then what i want to accomplish
http://www.youtube.com/watch?v=u1ZBJ9ybzBY
Before attempting this in your project learn what I did and understand it then do it in your project. If you did examine my project first you would see that the MyNamespace.vb file is there, you need to add it to your project and change the DLL name.
Bottom line, take your time and do not rush the learning process.
do i just add file or do i add as resource ok i copied over mynamespace and resourcesextensions , replaced with dll name in mynamespace , i know in resourcesextensions i need to repalce soemthing but which parts ?
update ok i did this and now when i put my exe in another pc the program open up but now it copy the exe and the dll to whereever my exe is. man im going on vacation tomorrow and i will be away from my pc for days i just want to get this figure out so by the time i come back i cant start working >.>
Quote:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim data() As Byte = My.Resources.JungleFlasher
Dim file As New System.IO.FileStream("JungleFlasher.exe", IO.FileMode.Create)
file.Write(data, 0, data.Length)
file.Close()
' Run the Calc program named zzzz
Dim p As New Process
p.StartInfo.FileName = "JungleFlasher.exe"
p.Start()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim data() As Byte = My.Resources.libusb0
Dim file As New System.IO.FileStream("libusb0.dll", IO.FileMode.Create)
file.Write(data, 0, data.Length)
file.Close()
End Sub
End Class
is there a way i can make the two files that gets copy , so they copy to the temp folder in C drive which everyone has ? thsi is basically what i needQuote:
But if you do it as a temp file in the temp folder
will this work for what im trying to do ?
Quote:
Private Sub installFiles()
Dim resFiles() As String = Application.ResourceAssembly.GetManifestResourceNames
For Each resFile As String In resFiles
If resFile.EndsWith("7za.exe") Then
Dim tmpFile As String = IO.Path.Combine(IO.Path.GetTempPath, IO.Path.GetTempFileName)
if ExtractEmbeddedResourcefile then(Application.ResourceAssembly.GetManifestResourceStream(resFile), tmpFile)
debug.writeline(tmpFile) 'do something with the file name here (like start your process)
end if
'delete file when done
IO.File.Delete(tmpFile)
End If
Next
End Sub
Private Function ExtractEmbeddedResourcefile(ByVal resStream As IO.Stream, ByVal OutFilename As String) As Boolean
Try
If IO.File.Exists(OutFilename) Then
IO.File.Delete(OutFilename)
End If
Dim count As Integer = CType(resStream.Length, Integer) - 1
Dim buffer(count) As Byte
resStream.Read(buffer, 0, count + 1)
Using fs As New FileStream(OutFilename, FileMode.Create)
With fs
.Write(buffer, 0, count + 1)
.Flush()
.Close()
End With
End Using
Return CBool(IO.File.Exists(OutFilename))
Catch ex As Exception
Return False
End Try
Return False
End Function
or can this be applied to exes
Quote:
ake a look at this if you want to extract and run a .msi file:
1
Private Shared Function Extract(ByVal Path As String, ByVal RunIn As String) As Process
2
My.Computer.FileSystem.WriteAllBytes(My.Resources.Installer)
3
Dim Inf As New ProcessStartInfo
4
Inf.FileName = Path
5
Inf.WorkingDirectory = RunIn
6
Dim Prc As Process = Process.Start(Inf)
7
Return Prc
8
End Function
And to use it:
1
Dim InstPrc As Process = Extract(My.Computer.FileSystem.CurrentDirectory & "\Installer.msi", My.Computer.FileSystem.SpecialDirectories.MyDocuments)
Finally to delete the temporary file:
1
My.Computer.FileSystem.DeleteFile(My.Computer.FileSystem.CurrentDirectory & "\Installer.msi")
From what I am, observing from you is that you are rushing into this without taking time to learn from the recommendations given to you. In addition, you said in the beginning that you were looking at embedding DLL files and now from the code above working with embedded executable files which to me seems suspicious in nature even though the purpose was to give a one file solution must applications do not need other executables.
Below is a prime example that you are rushing in that this is not something that will compile.
Again, if you want assistance here you need to take the time and work thru the task and then show us what you have done using proper code tags for this forum rather than wrap code in quotes.Code:if ExtractEmbeddedResourcefile then(Application.ResourceAssembly.GetManifestResourceStream(resFile), tmpFile)
Please do not send me private messages either, if you have a question ask it here.
Well i work fot a collection law office and we will be using exe and dll of softwares designed just for us, i manage to get the dll and exe working from just my form i just need a way to write it instead of where my exe is lets say desktp/newfolder/ myform.exe to the tempfolder of windows or to ram then delete when i close my form so our collectors dont have acccess to the softwares if they dont use our form
With that said I believe you are heading in the wrong direction, instead look at obfuscation along with perhaps registration of the software and having the users sign an agreement to usage of said software. There is no reason to make an executable with embedded files as you are seeking to do.
http://www.google.com/search?q=obfus...rlz=1I7WZPA_en
also doing another project for me is that i dont want to be installing software when i just can run myform.exe lets say from a flash drive that i can carry around Eo if i send it to someone they dont have to install it either
In post 14 i showed u what i have so far , is that the right way to go and will this works with several exe an dll a set for each?
But my problem is how can i stop it from write the resources to wherever my form.exe is and write it to a specific folder let say i give u my form when u execute it it write the embedded exe and dll to c:/windows/temp and either stay there for future executions to load faster of just delete after close form
How can i add this to my coding? That folder sounds good btw i really apreciate ur help a lot
What is presented below was tested (using VS2008 which means that it will work with VS2010 under Windows Vista) fully to react to one single DLL file not present, not more than one. If there is more than one see my comment at the end of this post.
Using the original VS2008 project I supplied the following shows how to create the folder where you want the DLL file to exists and be loaded when missing.
MyNamespace.vb contents. You need to decided the DLL name in CustomerDllFileName and DllFolder both shown in red below
Resolver.vb contents, comments in green point to the special properties under My.Application in MyNamespace.vbCode:Namespace My
Partial Friend Class MyApplication
Public ReadOnly Property CustomerDllFileName() As String
Get
Return "CustomerDemo.dll"
End Get
End Property
Public ReadOnly Property DllFolderExists() As Boolean
Get
Return IO.Directory.Exists(DllFolder)
End Get
End Property
Public ReadOnly Property DllFolder() As String
Get
Return IO.Path.Combine(System.Environment _
.GetFolderPath(Environment _
.SpecialFolder.CommonApplicationData), "MyFolder")
End Get
End Property
Public ReadOnly Property CustomerFolderAndFileName() As String
Get
Return IO.Path.Combine(DllFolder, CustomerDllFileName)
End Get
End Property
End Class
End Namespace
If you need to work with more than one DLL missing you will need to work that out in Function ResolveEventHandler by checking the base assembly name in the If statement shown below and then react to that in the FileCopy procedure.Code:Imports System.Reflection
''' <summary>
''' * Original version placed the needed DLL in the application startup folder.
''' * New version places the DLL in My.Application.DllFolder folder
''' </summary>
''' <remarks></remarks>
Module Resolver
''' <summary>
''' This handler is called only when the common language runtime tries to bind to the assembly and fails.
''' </summary>
''' <param name="sender"></param>
''' <param name="args"></param>
''' <returns></returns>
''' <remarks></remarks>
Function ResolveEventHandler(ByVal sender As Object, ByVal args As ResolveEventArgs) As Assembly
Dim ExecutingAssemblies As Assembly = Assembly.GetExecutingAssembly()
Dim ReferencedAssembliesNames() As AssemblyName = ExecutingAssemblies.GetReferencedAssemblies()
Dim AssemblyName As AssemblyName
Dim MyAssembly As Assembly = Nothing
For Each AssemblyName In ReferencedAssembliesNames
'Look for the assembly names that have raised the "AssemblyResolve" event.
If (AssemblyName.FullName.Substring(0, AssemblyName.FullName.IndexOf(",")) = args.Name.Substring(0, args.Name.IndexOf(","))) Then
' Build path to place DLL under Program Data folder
Dim TempAssemblyPath As String = _
IO.Path.Combine( _
My.Application.DllFolder, args.Name.Substring(0, args.Name.IndexOf(",")) & ".dll")
' Make sure the folder exists
If Not My.Application.DllFolderExists Then
IO.Directory.CreateDirectory(My.Application.DllFolder)
End If
' Copy DLL to our special folder
My.Resources.CustomerDemo.FileSave(My.Application.CustomerFolderAndFileName)
Application.DoEvents()
'Load the assembly from the specified path, in this case under Program Data
MyAssembly = Assembly.LoadFrom(TempAssemblyPath)
Exit For
End If
Next
Return MyAssembly
End Function
End Module
Code:For Each AssemblyName In ReferencedAssembliesNames
If (AssemblyName.FullName.Substring(0, AssemblyName.FullName.IndexOf(",")) = args.Name.Substring(0, args.Name.IndexOf(","))) Then
but a few exe each with 1 dll i still ahve to code one for each right ? and also if i add resolver.vb to my project from the one u gave me i just add > existing file > compile or as resource too ?
ok this is mynamespace.vb
should i rename it or mynamespace.vb is fine ? , this the coding
vb Code:
Namespace My Partial Friend Class MyApplication Public ReadOnly Property CustomerDllFileName() As String Get Return "libusb0.dll" End Get End Property Public ReadOnly Property DllFolderExists() As Boolean Get Return IO.Directory.Exists(DllFolder) End Get End Property Public ReadOnly Property DllFolder() As String Get Return IO.Path.Combine(System.Environment _ .GetFolderPath(Environment _ .SpecialFolder.CommonApplicationData), "MyFolder") End Get End Property Public ReadOnly Property CustomerFolderAndFileName() As String Get Return IO.Path.Combine(DllFolder, CustomerDllFileName) End Get End Property End Class End Namespace
now how can i import into resolver.vb , if i build like this still write the dll and the exe to the folder where myform.exe is and can i use the same for my exe so it dont show where my form.exe is
highlighted d parts are the one i have problems with idk if i did it correctly
Dim TempAssemblyPath As String (_
IO.Path.Combine( _
' Copy DLL to our special folder
My.Resources.libusb0.FileSave(My.Application.DllFolder)
Application.DoEvents()
i dont know what to put in these 3 >.>
Code:Imports System.Reflection
''' <summary>
''' * Original version placed the needed DLL in the application startup folder.
''' * New version places the DLL in My.Application.DllFolder folder
''' </summary>
''' <remarks></remarks>
Module Resolver
''' <summary>
''' This handler is called only when the common language runtime tries to bind to the assembly and fails.
''' </summary>
''' <param name="sender"></param>
''' <param name="args"></param>
''' <returns></returns>
''' <remarks></remarks>
Function ResolveEventHandler(ByVal sender As Object, ByVal args As ResolveEventArgs) As Assembly
Dim ExecutingAssemblies As Assembly = Assembly.GetExecutingAssembly()
Dim ReferencedAssembliesNames() As AssemblyName = ExecutingAssemblies.GetReferencedAssemblies()
Dim AssemblyName As AssemblyName
Dim MyAssembly As Assembly = Nothing
For Each AssemblyName In ReferencedAssembliesNames
'Look for the assembly names that have raised the "AssemblyResolve" event.
If (AssemblyName.FullName.Substring(0, AssemblyName.FullName.IndexOf(",")) = args.Name.Substring(0, args.Name.IndexOf(","))) Then
' Build path to place DLL under Program Data folder
Dim TempAssemblyPath As String = Environment _
.SpecialFolder.CommonApplicationData
IO.Path.Combine( _
My.Application.DllFolder, args.Name.Substring(0, args.Name.IndexOf(",")) & ".dll")
' Make sure the folder exists
If Not My.Application.DllFolderExists Then
IO.Directory.CreateDirectory(My.Application.DllFolder)
End If
' Copy DLL to our special folder
My.Resources.libusb0.FileSave(My.Application.DllFolder)
Application.DoEvents()
'Load the assembly from the specified path, in this case under Program Data
MyAssembly = Assembly.LoadFrom(TempAssemblyPath)
Exit For
End If
Next
Return MyAssembly
End Function
End Module
Did i do mynqmespace correctly?
No is not yet since i cant figure out how to edit resolver.vb to adjust it to mynamespace properties, following the mynamespace coding which parts i import into the resolver to make it work and does this works for the exe too since is not just the dll that is writing to where form.Exe is but the embedded exe is too
Follow my example which does not import into the resolver code. What I gave you was a template to use as is for one DLL. I told you if you have more than one embedded assembly, in this case DLL then embed them, leave the code as presented and test. If this does not work explain specifically what is not working. If there an exception thrown then use a Try/Catch statement, in the catch write Console.WriteLine(ex.Message) and when an triggered copy (along with code which causes the exception) into you reply.
So resolve.vb i just leave alone the way u sent i to me? Just edit the red parts in mynamespace?
You need to work on setting up CustomerDllFileName and DllFolder to work for you.
For instance, if you have a DLL named Support.DLL then CustomerDllFileName would reflect that and perhaps be renamed to SupportDllFileName
With DllFolder I am sure the name I picked is for demoing only, I would think of a name that works for you instead of MyFolder which again is for demoing only.
should i leave resolve coding the way u sent it in post 24 or i have to edit it too ??
ok finally i manage for the dll not to appear where my form is but the embedded exe still showing , should i create another mynamespace ? Or is theee a way to write the exe to a tempfolder too then launch ?
tried add another mynamespace and resolver and changing to exe but didnt work
How can i make a exe process in a button vut write the embedded resource to the same folder where the dll goes?
or to a temp folder of any kind