Support Forums
Help with coding - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Visual Basic and the .NET Framework (https://www.supportforums.net/forumdisplay.php?fid=19)
+---- Thread: Help with coding (/showthread.php?tid=23862)



Help with coding - jerrojack - 12-14-2011

Help me please to do this in vb.net
1.How do i copy my resources(which is an .exe) to a specific directory and run it.

2.How can i run an .exe file or .rar which i imported into the resources of my project by pressing button .

I tried the following codes but wasnt successful.

Process.start(my.resources.filename)

Shell(my.resources.filename)

Do help me out


RE: Help with coding - AceInfinity - 12-29-2011

Here's my demo for you.

Code:
Dim resFile As Byte() = My.Resources.file
Dim WritePath as string = "MyFolderPathHere\myfile.exe"
Dim fstream As New FileStream(WritePath, FileMode.Append)
fstream.Write(resFile, 0, resFile .Length)
fstream.Close()

What we're doing here is defining a byte array from the resource named "file" as an executable i've added as a project resource, and writing those bytes to a file i'm creating in it's own path with the myfile.exe name.

Very very easy there buddy. You can also look into ByteReader and ByteWriter in the System.IO namespace if you want.

Now to run this:
Code:
Process.Start(WritePath)

This won't work:
Code:
Process.start(my.resources.filename)

Because Process.Start() doesn't take a byte array as input which is what my.resources.filename really is, it's not a string, it's a byte array.