As part of my program, how do I enable user to define install location

razz

Well-known member
Joined
Oct 11, 2008
Messages
67
Programming Experience
Beginner
My freeware program launches 50 freeware programs and provides a guide for PC maintenance and health. As mentioned in another post, my program was reviewed on Sofpedia. One thing the Reviewer criticized was the fact that my program requires the user to install these 50 programs in the default locations (usually C:\Program Files\x). The reviewer thinks it would be best if the user can install to any location he/she desires and my program be able to point to the proper location when launching the application. He certainly has a point.

Would anyone know how to accomplish this in VB 2008?

Any help will be greatly appreciated.
 
Define install location?
Perhaps use a browse button w/ textbox?
Browse button code:
VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim MyFolderBrowser As New System.Windows.Forms.FolderBrowserDialog

' Descriptive text displayed above the tree view control in the dialog box
MyFolderBrowser.Description = "Select the Folder"

' Sets the root folder where the browsing starts from
'MyFolderBrowser.RootFolder = Environment.SpecialFolder.MyDocuments

' Do not show the button for new folder
MyFolderBrowser.ShowNewFolderButton = False

Dim dlgResult As DialogResult = MyFolderBrowser.ShowDialog()

If dlgResult = Windows.Forms.DialogResult.OK Then
TextBox1.Text = MyFolderBrowser.SelectedPath
End If

End Sub
Make sure to have a textbox right next to it.
Now then, TextBox1.Text should be the folder.
So, wherever you have the install location as "C:\Program Files" just change that to TextBox1.Text
 
Thanks Untamed. Your time and effort is really appreciated. Things can be very tough for a beginner like me when you try to accomplish certain things.

Thanks again! :D
 
Thanks Untamed. Your time and effort is really appreciated. Things can be very tough for a beginner like me when you try to accomplish certain things.

Thanks again! :D

No problem. Tell me if this works out or not. Also, FYI, I haven't even been working with VB for 2 weeks yet :p
 
Hi Untamed. I created a mini program to test the code you supplied and it does indeed work. However, unless I am really missing something, it would not suit as a solution to what I am trying to accomplish.

Let me try to better explain what it is I require. Basically, besides providing a guide, my program launches freeware applications that have already been installed on the user's PC. For example, one of the 50 applications that my program can launch is CCleaner. From my program's GUI the user clicks the appropriate button and CCleaner launches (from that point the user runs CCleaner via it's own GUI). Currently for CCleaner to launch from my program, the path must be "C:\Program Files\CCleaner\CCleaner.exe" (i.e. if the user has for some reason installed CCleaner in any other folder, then my program would not be able to find it and as of now (thanks to you) an error message would say "File not Found".)

Is there some way for the user to initially inform my program where the file is (if it is not installed in that particular application's default install location) and have this information stored within my program so the next time it is not necessary to repeat the procedure?

If you wish to get a better idea of my program and what I am trying to explain, you can download only the binary file: http://a-z-freewarelauncher.yolasite.com/resources/AZFLv3_Black.zip
 
Hmm... how about creating a config file?
Also, a config screen [another windows form] for your program.
There are 50 browse buttons+textboxes, each one with a program name next to it. The browse button only allows them to choose EXE. Once all 50 textboxes are filled with the user-chosen locations for each of the 50 applications, you hit a save button, where it saves all these locations in a text file.
Then, just make sure the user doesn't touch the config file and keeps it in the same folder as the program. The program reads the text file, and looks for a variable on a line of that text file that represents a programs location.
 
That sounds like the perfect solution Untamed.
I realize that I am probably asking silly questions, but can you tell me how to go about creating a config file and config screen? I was not able to figure out how to accomplish this :(

Thank you for your time, I really appreciate it!
 
Config Screen:
Big screen that has 50 textbox, 50 browse button, 50 labels.
Textbox + Browse Button for getting program location.
Labels for telling people what that box is for[what program].
You'll also need 1 Save button.
The save button will first check to see if the config file exists, and if it doesn't, it creates it.
Then, the save button reads the textboxes and saves them into the config file.
Then, the program reads the config file, converts one chosen line of the text file into a variable string, and launches the application using that string.
 
I fully understand the master plan and the overall picture and I agree it would work perfectly to accomplish what is desired.

The problem for me is getting there.

I think I would have no problem up till creating the "save button".

What would be the required code to direct the save button to accomplish what needs to be accomplished?

Sorry to be a pest.

Thanks!
 
Here is a code you could use if there were 2 text boxes. Just change it a tad for 50 text boxes. Also, you'll need your program to be able to read the text file.

I am sure it is possible... you'll need to look at a certain line... like find where the line says "Program1" and then get the C: stuff that is on that line, after the Program1. Or... you could just try plain viewing text of a line.

Also, you may want to rearrange the code so that the file makes a new config file whenever the person saves it, so that it doesn't write too many lines.

Also, I am sure there is a simpler way to do the textboxes, like something that could check all 50 textboxes in only a few lines of code... but I am not 100% sure how to do that.
VB.NET:
    Private Sub ButtonSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSave.Click
        Dim FileLoc = My.Application.Info.DirectoryPath.ToString & ".\" & "config.txt"
        Dim MyFile As New FileInfo(FileLoc)
        If MyFile.Exists Then
        Else
            Dim oFile As System.IO.File
            Dim oWrite As System.IO.StreamWriter
            oWrite = oFile.CreateText("config.txt")
            oWrite.Close()
        End If
        If TextBox1.Txt = "" Then
            MsgBox("Please fill out all configuration locations!")
        ElseIf TextBox2.Txt = "" Then
            MsgBox("Please fill out all configuration locations!")
        Else
            Dim oFile As System.IO.File
            Dim oWrite As System.IO.StreamWriter
            oWrite = oFile.AppendText("config.txt")
            oWrite.WriteLine("Program1" & TextBox1.Txt)
            oWrite.WriteLine("Program2" & TextBox2.Txt)
            oWrite.Close()
        End If
    End Sub
 
Thank you again Untamed. I will play around with this idea and see what happens. Again, thanks for all your time, I sincerely appreciate it!
 
Back
Top