none
How to run exe file from recources RRS feed

  • Question

  • I do this:

    Dim ParentDirectory As String = System.IO.Directory.GetParent(System.Windows.Forms.Application.StartupPath).FullName
        Dim ProgramPath As String = ParentDirectory & "\resources\MyApp.exe" 
        System.Diagnostics.Process.Start(ProgramPath)

    Now this ain't helping me anymore because the Recources folder isn't a subfolder in bin folder, it is a folder located in the same folder as bin. So what can i do to go to that directory by replacing this?

    Dim ParentDirectory As String = System.IO.Directory.GetParent(System.Windows.Forms.Application.StartupPath).FullName
        

    Saturday, March 24, 2018 4:38 PM

All replies

  • Resources is a part of the assembly. 

    Therefore it can be 

    System.Diagnostics.Process.Start(My.Resources.ProgramPath)

    To set it you use this, where you come with project properties and then select resources


    Success
    Cor

    Saturday, March 24, 2018 5:12 PM
  • I don't really like this idea, for security reasons, but the question was asked recently:

    https://social.msdn.microsoft.com/Forums/Lync/en-US/1f770bbb-a683-4b38-9043-8bb4675f6cf5/how-run-an-exe-from-resources-in-vb-net?forum=vbgeneral


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Saturday, March 24, 2018 5:28 PM
  • I agree with Paul on this but if you truly need to do this with good reason then download the following which shows how to extract in this case an Excel file and access it via Office automation.

    Cor has given you where to start.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Saturday, March 24, 2018 6:07 PM
    Moderator
  • Perhaps you need to explain what you are trying to do using words instead of sample code. The sample code is very confusing because resources are compiled and linked into the executable.

    Managed applications don't have a linker (there has to be one internally however) but if you don't know what that is then ignore this sentence.

    For every resource there is a corresponding type. Most resources in managed applications are strings. Unmanaged applications store things like icons for the application as resources and managed applications probably do too but I don't know the details. To store an exe I am nearly certain you want create a BLOB resource or at least a custom resource. I am more familiar with doing that type of thing for managed applications.

    Try the following for educational purposes. Create a new VB.Net project if you want to to try this. Then add an icon; go to the "General" node for new items and look for icons. Then in Solution Explorer look for "Resource1.resx". If it is there then open it. If it is not there then I don't know what to do. In the top is a drop-down for "Add Resource". Click on "Add Existing File..." then browse to the solution's directory and select the icon. It will say it already exists and asks if you want to replace it; I guess that normally we would add a file from somewhere else and when it is added to the project it gets copied. Note that in the "Resource1.resx" window the left-most control is for the resource type. See if you can figure out how to access the icon from your program. I am sure I can figure it out but see if you can. If you can do all that then you will have the fundamentals you need to store a resource and access it.



    Sam Hobbs
    SimpleSamples.Info


    Saturday, March 24, 2018 9:10 PM