Page 1 of 1
How do i launch this from resourses
Posted: Sat Oct 13, 2012 5:58 pm
by muttley1968
i need to know a way to know the location of a resourses file invb.net see i have a .bat file that needs to take something from a resorse file and launch it but how do i do that or do i need to right them all to a file in appdata :P
need to know this ASAP please all help is apreashated
Re: How do i launch this from resourses
Posted: Sat Oct 13, 2012 6:17 pm
by Scottie1972
Make sure that the resource is an "EMBEDDED RESOURCE" in the reources properties menu.
Right-Click the resource , choose Proerties, Build Type I think.. choose EMBEDDED RESOURCE.
Code: Select all Public Sub SaveToDisk(ByVal resourceName As String, ByVal fileName As String)
Dim assy As [Assembly] = [Assembly].GetExecutingAssembly()
For Each resource As String In assy.GetManifestResourceNames()
If resource.ToLower().IndexOf(resourceName.ToLower) <> -1 Then
Using resourceStream As System.IO.Stream = assy.GetManifestResourceStream(resource)
If resourceStream IsNot Nothing Then
Using reader As New BinaryReader(resourceStream)
Dim buffer() As Byte = reader.ReadBytes(CInt(resourceStream.Length))
Using outputStream As New FileStream(fileName, FileMode.Create)
Using writer As New BinaryWriter(outputStream)
writer.Write(buffer)
End Using
End Using
End Using
End If
End Using
Exit For
End If
Next resource
End Sub
this will save the resources as a file to your drive for local access
To Use:
Code: Select all SaveToDisk(My.Resources.RESOURCEFILE, Drive:\\PATH\FILENAME.EXT)
'or
SaveToDisk(My.Resources.RESOURCEFILE,Application.StartUpPath & "\filename.ext")
then you just do a simple process.start()
Code: Select all Process.start("path/to/saved_resource.ext") ' or the .BAT file you was talking about.
Re: How do i launch this from resourses
Posted: Sat Oct 13, 2012 7:04 pm
by muttley1968
Ive done this but when i go to debug and try it says the files does not exist and is not their i used it like this is that right
Code: Select all Public Sub SaveToDisk(ByVal resourceName As String, ByVal fileName As String)
Dim assy As [Assembly] = [Assembly].GetExecutingAssembly()
For Each resource As String In assy.GetManifestResourceNames()
If resource.ToLower().IndexOf(resourceName.ToLower) <> -1 Then
Using resourceStream As System.IO.Stream = assy.GetManifestResourceStream(resource)
If resourceStream IsNot Nothing Then
Using reader As New BinaryReader(resourceStream)
Dim buffer() As Byte = reader.ReadBytes(CInt(resourceStream.Length))
Using outputStream As New FileStream(fileName, FileMode.Create)
Using writer As New BinaryWriter(outputStream)
writer.Write(buffer)
End Using
End Using
End Using
End If
End Using
Exit For
End If
Next resource
End Sub
Private Sub CrystalClearButton9_Click(sender As Object, e As EventArgs) Handles CrystalClearButton9.Click
SaveToDisk(My.Resources.booter, Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\booter.bat")
Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\booter.bat")
End Sub
Re: How do i launch this from resourses
Posted: Sat Oct 13, 2012 7:32 pm
by Scottie1972
for some reason, the code can not find the exstracted resource file.
did you set the resource file as an EMBEDDED RESOURCE in the properties menu?
Re: How do i launch this from resourses
Posted: Sat Oct 13, 2012 7:39 pm
by muttley1968
Yes I did
Does it need to run as admin?
Re: How do i launch this from resourses
Posted: Mon Oct 15, 2012 8:54 pm
by mandai
I can confirm the above code works if you are trying to extract a named embedded resource file from the project.
Though it would appear the first parameter of the SaveToDisk method takes the file name, not the resource contents.
You shouldn't need to run it as admin either.