none
How to Give Path to INI file that is inside My Resources RRS feed

  • Question

  • Hello I start new project in Visual Studio. I am a New in visual studio .now I need help I add INI file to Resources Now I want to know how to give a path for button that I made that run exe file that is inside my Resources . but for this exe file to work is need this INI file . so what I need if someone here can tell me witch commend I need to put in the button to make a path to this INI file that Is inside my Resources . thanks to all help 


    Sunday, November 5, 2017 4:45 PM

All replies

  • Hopefully you realize that you must extract the resource to disk to run it and if it needs a .ini file which is also in resources it must be extract to the same path.

    By default a exe file created in VB.NET (of C#) when it needs to use a file such as a .ini file and is not given a path it will look in the current directory from which is was executes from.


    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

    Sunday, November 5, 2017 6:45 PM
    Moderator
  • Extract it in the application directory
    Sunday, November 5, 2017 6:59 PM
  •  Did you use the steps shown in the link below to add the files to your application's resources?

     How to: Add or Remove Resources

     If you did this,  then you would not use a path to the exe or ini file in the resources.  They are embedded into your application's exe file and you would need to write both files back to the hard drive in order to use them.  You would write them to a folder of your choice (not a protected folder) and name them to whatever name you want.  Use the File Class to do this.

     This writes an exe file and an ini file to a directory on the hard drive and then executes the exe.

    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim MyFolder As String = "C:\testfolder\SomeFolder"
            Dim IniFilename As String = IO.Path.Combine(MyFolder, "MyIniFile.ini")
            Dim ExeFilename As String = IO.Path.Combine(MyFolder, "MyExeFile.exe")
            If Not IO.File.Exists(ExeFilename) Then IO.File.WriteAllBytes(ExeFilename, My.Resources.MyExeProgram)
            If Not IO.File.Exists(IniFilename) Then IO.File.WriteAllText(IniFilename, My.Resources.MyIniFile)
            Process.Start(ExeFilename)
        End Sub
    End Class
    


    If you say it can`t be done then i`ll try it

    Sunday, November 5, 2017 7:11 PM