|
-
May 12th, 2009, 05:30 PM
#1
Thread Starter
Junior Member
Please help .exe issues
im pretty new to VB 2008 and programming in general
here's my problem
im using a button_click event to run a .exe i am adding it as a resource and in run time the button_click wont work, i cant figure out the code to make it run on from the click event
sorry for sounding like a complete noob but someone please help me out with this line of code so i can get my .exe to run at runtime
-
May 12th, 2009, 05:38 PM
#2
Frenzied Member
Re: Please help .exe issues
process.start("Address and name of exe with extension")
-
May 12th, 2009, 05:43 PM
#3
Thread Starter
Junior Member
Re: Please help .exe issues
your a life saver
one more question while im here lol when i publish my app i want to be able to transfer between pc's but dont want to have a folder full of the small .exe's next to my app as there is really no point, can i somehow embed them into my app so i can just run my app push a button an the .exe i added will run
-
May 12th, 2009, 05:52 PM
#4
Frenzied Member
Re: Please help .exe issues
Once you publish your project .net creates a folder with all the necessary files to install it on any pc.
Once installed you can delete the folder and start the program as with any other program from Start/All Programs.
-
May 12th, 2009, 05:57 PM
#5
Re: Please help .exe issues
Are asking whether or not you can embed the executable files as resources in your application?
In which case the answer is yes, but you cant run them directly from within the resources (at least I don't think you can) - you would have to retrieve the files and write them to the file system in order to run them.
I'm not sure its the world's greatest idea to do this although I can see why you might want to keep the place tidy by hiding the EXEs until they are actually needed.
Last edited by keystone_paul; May 12th, 2009 at 06:01 PM.
-
May 12th, 2009, 06:02 PM
#6
Thread Starter
Junior Member
Re: Please help .exe issues
 Originally Posted by keystone_paul
Are asking whether or not you can embed the executable files as resources in your application?
yeah i think so, i dont want files in a folder in the same folder as my app i want them all within my app's .exe (so one .exe on another pc)
i have added one file to the resorces and i want this to run from my button click so i use the process.start and im gettin win32 exception was unhandled error
-
May 12th, 2009, 06:19 PM
#7
Re: Please help .exe issues
What does your process.start line look like : you need to give it a path to the file on the file system so unless you've saved a copy of the executable from my.resources, you can't just pass in the resource.
-
May 12th, 2009, 06:21 PM
#8
Thread Starter
Junior Member
Re: Please help .exe issues
process.start ("C:\Users\me\Desktop\folder\programs.exe") i have it added it to the Resources and it's showing in as a Resource in soloution explorer
-
May 12th, 2009, 06:28 PM
#9
Re: Please help .exe issues
Where did that path come from? I assume programs.exe is the name of your embedded executable?
Don't get confused by the solution explorer view - just because it shows in there doesn't mean that there is an executable file in a sub-folder off your project's root folder.
Like I say - you will need to extract the EXE from my.resources and write it to the hard drive manually.
-
May 12th, 2009, 06:32 PM
#10
Thread Starter
Junior Member
Re: Please help .exe issues
thats the path of where the program i need to run from the button_click ok i edited it abit for obvious reason's
why would i need to extract it as i can run the program from that path by clickin on that exe its already on my HDD its just in a folder on my desktop waiting to be embeded into my app
-
May 12th, 2009, 06:37 PM
#11
Re: Please help .exe issues
Right, but when you deploy your program onto another machine they aren't going to have the exe in that path are they? I thought that was the whole point - you want to have the exe embedded in your own application and not on the file system?
Or am I missing the point?
-
May 12th, 2009, 06:40 PM
#12
Thread Starter
Junior Member
Re: Please help .exe issues
Sorry i was getting a bit confused but im with you now yes i want it embedded in my application
-
May 12th, 2009, 06:48 PM
#13
Re: Please help .exe issues
OK - so at the point at which the user wants to run this embedded exe you need to take a copy of your resource and write it to disk, run it using process.start and then presumably delete it again.
This code (courtesy of .Paul. on another thread) allows you to write out the resource file :
Code:
Dim size As Long = My.Resources.MyProgram.Length - 1
Dim buffer(CInt(size)) As Byte
Dim offset As Integer = 0
Dim count As Integer = CInt(size)
Dim returnValue As Integer
returnValue = My.Resources.MyProgram.Read(buffer, offset, count)
Dim fs As New IO.FileStream(IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.Temp, "myfilename.exe"), IO.FileMode.Create)
fs.Write(buffer, 0, buffer.Length)
fs.Close()
You just replace MyProgram with the name of the resource, and set the appropriate filename in place of myFilename.exe
-
May 12th, 2009, 06:59 PM
#14
Thread Starter
Junior Member
Re: Please help .exe issues
Thank You so much i have one error thou
Code:
returnValue = My.Resources.MyProgram.Read(buffer, offset, count)
Dim fs As New
i have added my file name > program.exe and my error is 'exe' is not a member of 'system.Array'
i will be hittin up yopur rep you have helped me out so much so far
-
May 12th, 2009, 07:11 PM
#15
Re: Please help .exe issues
When you type in "my.resources." you should get a dropdown of the resources available - make sure that the name of your resource is in there. I think the name will probably have the ".exe" removed, ie instead of
returnValue = My.Resources.Program.Exe.Read(buffer, offset, count)
it should probably be
returnValue = My.Resources.Program.Read(buffer, offset, count)
-
May 12th, 2009, 07:15 PM
#16
Thread Starter
Junior Member
Re: Please help .exe issues
yeah the so i type
My.Resorces.myprogram(is in the intelisence).read.....
im still getting the error
but its the ".Read" this time
-
May 12th, 2009, 08:12 PM
#17
Thread Starter
Junior Member
Re: Please help .exe issues
-
May 13th, 2009, 02:12 AM
#18
Re: Please help .exe issues
Sorry it was 1.15am at the time of my last post and I need sleep every few days!
I over complicated things before by borrowing someone's existing code rather than writing and testing from scratch - probably because it was 1.15! This should do the trick for you - I've written and tested it this morning.
Code:
Private Sub SaveResource(ByVal ResName As String, ByVal OutPath As String)
' Get the Embedded Resource
Dim ResStream As Byte() = My.Resources.ResourceManager.GetObject(ResName)
Dim oFileStream As System.IO.FileStream
oFileStream = New System.IO.FileStream(OutPath, System.IO.FileMode.Create)
oFileStream.Write(ResStream, 0, ResStream.Length)
oFileStream.Close()
oFileStream.Dispose()
End Sub
So paste that sub into your code and call it, passing in the name of the resource and the filename you want to save it as. This will then save the executable to disk. It could use some error trapping really but its just there to demonstrate the principle.
If I were you I'd make my code a bit more sophisticated so you aren't extracting and deleting all the time. Id create a temporary folder to hold them while your program is running and either a) on startup extract all the exes from the resource file or b) when you need to run a specific one first check to see if it has already been extracted. Then when your application is closing delete all the exes in your folder.
-
May 13th, 2009, 03:17 PM
#19
Thread Starter
Junior Member
Re: Please help .exe issues
Seriuosly not getting this i have tried your way here i call it and nothing happens my resource (Myprogram) doesn't do anything i just want it to run from the window's Temp folder when i click the button and (myprogram).exe run's im either not gettin this or somthings not right
-
May 13th, 2009, 03:22 PM
#20
Re: Please help .exe issues
 Originally Posted by gumball
Seriuosly not getting this i have tried your way here i call it and nothing happens my resource (Myprogram) doesn't do anything i just want it to run from the window's Temp folder when i click the button and (myprogram).exe run's im either not gettin this or somthings not right
So can you show us what you've got now then in terms of code?
-
May 13th, 2009, 03:27 PM
#21
Thread Starter
Junior Member
Re: Please help .exe issues
im on 2 forum's as i was up till 4am tryin to get this running so i think im getting 2 lot's of ways to do this
im using what you told me to use im not gettin it to run at all once i have it running i will then try fine tune the code
-
May 13th, 2009, 03:36 PM
#22
Re: Please help .exe issues
OK - I can't really help tell you what you've got wrong without seeing how you've implemented it.
The above code does work for extracting an executable from an application's resources and saving it to your hard drive so i'd step through your code, check that the file has been extracted, try running it from the location that you've saved it in manually. If that works then its the code thats starting the process which isn't working.
-
May 13th, 2009, 03:42 PM
#23
Thread Starter
Junior Member
Re: Please help .exe issues
Just to make sure im doing it right then
vb Code:
Private Sub SaveResource(ByVal ResName As String, ByVal OutPath As String) ' Get the Embedded Resource Dim ResStream As Byte() = My.Resources.ResourceManager.GetObject[U](ResName)[/U] Dim oFileStream As System.IO.FileStream oFileStream = New System.IO.FileStream([U]OutPath[/U], System.IO.FileMode.Create) oFileStream.Write(ResStream, 0, ResStream.Length) oFileStream.Close() oFileStream.Dispose() End Sub
the 2 underlined parts need to be changed (MyProgram) and then where the outputpath is ie the temp folder in windows ?
-
May 13th, 2009, 03:43 PM
#24
Re: Please help .exe issues
You don't need to do all that byte writing and what not. This is a very simple thing to do in 3 lines of code.
If you want to step back from your current project just to see how this works, just create a new winforms project. In the resources tab, select files as the type of resource (or hit ctrl+5 shortcut).
I used notepad.exe from the c:\windows\ directory because i know you have it on your machine there.
So I copied notepad.exe from the windows directory to the file resources section in my project, and it shows up as notepad (without the .exe part). It is stored in YOUR program as a series of bytes.
Now the code:
Code:
'GET A TEMP FILE FOLDER LOCATION, APPEND A FILE NAME ON IT
Dim TempFileLocation = IO.Path.GetTempPath & "\notepad.exe"
'WRITE ALL THE BYTES FROM THE STORED FILE TO THIS TEMP FILE
My.Computer.FileSystem.WriteAllBytes(TempFileLocation, My.Resources.notepad, False)
'LAUNCH THIS TEMP FILE
Process.Start(TempFileLocation)
-
May 13th, 2009, 03:49 PM
#25
Re: Please help .exe issues
 Originally Posted by gumball
Just to make sure im doing it right then
vb Code:
Private Sub SaveResource(ByVal ResName As String, ByVal OutPath As String)
' Get the Embedded Resource
Dim ResStream As Byte() = My.Resources.ResourceManager.GetObject[U](ResName)[/U]
Dim oFileStream As System.IO.FileStream
oFileStream = New System.IO.FileStream([U]OutPath[/U], System.IO.FileMode.Create)
oFileStream.Write(ResStream, 0, ResStream.Length)
oFileStream.Close()
oFileStream.Dispose()
End Sub
the 2 underlined parts need to be changed (MyProgram) and then where the outputpath is ie the temp folder in windows ?
Are you actually calling process start to launch the program anywhere?
Kleinma's solution is a neater one for extracting the file, but at the end of the day will do the same thing, so I think the problem lies in when you launch the file.
Have you checked that after calling this routine the executable file exists where you think it is?
-
May 13th, 2009, 04:00 PM
#26
Thread Starter
Junior Member
Re: Please help .exe issues
Thank you both so much for all your help and not losing it with me i know im hard work lol
kleinma you are a star mate it work's and i now know what i was doing wrong thank you ill hit that REP button now
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|