Question[Help]Run Application from resources

Posts 1–6 of 6 · Page 1 of 1
[Help]Run Application from resources
I have an exe program in my resource folder. How can i run it when i click a button?
Try this
Name Space
[php]
Imports System.IO
[/php]

Now this in a button click (or whet ever triggers the event)

[php]
Dim RPath As String = Application.StartupPath & "\File.exe" 'File.exe will be a temp name given to your exe, you can make it anything you want, or keep it as is.

' Will create the file with the given name
Using CreateFile As New FileStream(RPath, FileMode.Create)
CreateFile.Write(My.Resources.YourResource, 0, My.Resources.YourResource.Length)
End Using
' Start the application
Process.Start(RPath)
[/php]

Note: "Your Resource" in my code example above needs to be the EXE name without the exe extension, so for example, if you add notepad.exe as a resource, then the code would be

[php]
Dim RPath As String = Application.StartupPath & "\File.exe"

Using CreateFile As New FileStream(RPath, FileMode.Create)
CreateFile.Write(My.Resources.Notepad, 0, My.Resources.Notepad.Length)
End Using

Process.Start(RPath)
[/php]

added to snippets vault post 1

how do you delete the file after the program closes.
[php]
Dim DeleteFile As String

DeleteFile = "Filepath \Filename.extentions"

If System.IO.File.Exists(DeleteFile) = True Then

System.IO.File.Delete(DeleteFile)

End If
[/php]
btw is it possible to save it in a temperary folder in appdata/local/
Yes,

Create a directory with

[php]
Directory.CreateDirectory(directory to create)
[/php]

Just change this line to match that directory

[php]
Dim RPath As String = Application.StartupPath & "\File.exe" 'File.exe will be a temp name given to your exe, you can make it anything you want, or keep it as is.
[/php]

Make it whatever path you like,

then delete the path (not just the exe) Delete the Folder

[php]
If System.IO.Directory.exists(Youe filr path) then _
System.io.directory.delete(your file path, true)
[/php]

Or extract the file to the temp folder of the OS and when the user restarts the computer it will be deleted.


Posts 1–6 of 6 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us