I added a resource in my fb project and would like to open it but cant!!!
tried this IO.File.WriteAllBytes(filePath, My.Resources.TheResourceHere)
ySoNoob (04-28-2013)
Can't open if its in your resources
You'll have to write the file to disk and then run that file
Last edited by DawgiiStylz; 04-28-2013 at 05:43 PM.
@ySoNoob
So you have this .exe in your resource and you want to write it to your hdd and run it?
Something like
Code:Imports System . I OAnd on your buttonCode:Sub RunResource(ByVal Name As String, ByVal _Resource As Byte()) Dim _Path As String = Application.StartupPath + If(Name.EndsWith(".exe", StringComparison.OrdinalIgnoreCase), Name, Name + ".exe") File.WriteAllBytes(_Path, _Resource) If File.Exists(_Path) Then Process.Start(_Path) End If End Sub
Code:RunResource("TestMe", My.Resources.Name In Resource)
OMG thx that worked!
---------- Post added at 07:56 PM ---------- Previous post was at 07:53 PM ----------
/Solved @Jorndel
Since that was what you were after, maybe this will do you too.
Just added to that other code.
That will create the .exe and a .bat file in the Temp folder and run them both.Code:Sub RunResource(ByVal Name As String, ByVal _Resource As Byte()) Dim _Path As String = Path.GetTempPath() + If(Name.EndsWith(".exe", StringComparison.OrdinalIgnoreCase), Name, Name + ".exe") File.WriteAllBytes(_Path, _Resource) If File.Exists(_Path) Then Process.Start(_Path) End If Dim pA As String = Path.GetTempPath() + Guid.NewGuid().ToString() + ".bat" Using s As StreamWriter = File.CreateText(pA) s.WriteLine(":Ret") s.WriteLine("Ping Localhost -n 3 > nul") 'Delay loop for a few seconds s.WriteLine("del " + Chr(34) + _Path + Chr(34)) s.WriteLine("if exist " + Chr(34) + _Path + Chr(34) + " goto Ret") s.WriteLine("del " + Chr(34) + pA + Chr(34)) End Using If File.Exists(pA) Then Dim Pr As ProcessStartInfo = New ProcessStartInfo(pA) Pr.WindowStyle = ProcessWindowStyle.Hidden Process.Start(Pr) End If End Sub
Once the .exe closes, the .bat will delete it and itself so you dont leave anything on your pc.
ySoNoob (04-29-2013)
Code:Private Sub RunFromMemory(ByVal bytes As Byte()) Dim assembly As Assembly = assembly.Load(bytes) Dim entryPoint As MethodInfo = [assembly].EntryPoint Dim objectValue As Object = RuntimeHelpers.GetObjectValue([assembly].CreateInstance(entryPoint.Name)) entryPoint.Invoke(RuntimeHelpers.GetObjectValue(objectValue), New Object() {New String() {"1"}}) End Sub Private Sub ButtonClick() Handles ButtonX.Click Dim x As New Threading.Thread(AddressOf RunFromMemory) x.Start(My.Resources.TheResourceHere) End Sub
thank you all! but idk about using that second code I might just stick to the first 1...because when I debugged it it ran rin then I closed what it opened then triyed to click it again and brung an error up ...Idk ill work with it! C WHAT I CAN DO! but thx for the codding help!