Solved

how to open a vb program from a file created by the same program?

Posted on 2014-12-09
1
204 Views
Last Modified: 2014-12-10
Hi

Im create an example project that has this options:
"create test file"
"load test file"
"register .test extension"

In the option "create test file" I created the following file:
<?xml version='1.0' encoding='utf-8'?>
<master>
     <test>hello</test>
</master>

Open in new window


In the option "load test file" I created a function that read the content of the test file and present a msgbox with content of the "test" tag using a custom function called loadfromfile("myfile.test").

In the option "register .test extension" I register the ".test" extension on the computer and I associated it with the compiled project.

all of this options works without problems

I would like to know if it is possible to open the compiled program from the files created by himself and catch the name of the file that is open the program to call the my function loadfromfile
0
Comment
Question by:altariamx2003
1 Comment
 

Accepted Solution

by:
altariamx2003 earned 0 total points
ID: 40492610
I found the solution by myself

The solution is in two parts

1.- Associate a the custom file type (generated by the same program) with your application
    Private Shared Sub AssociateFile(ByVal extension As String, ByVal name As String, ByVal description As String, ByVal iconPath As String, ByVal applicationPath As String)

        'Validate arguments
        If String.IsNullOrEmpty(extension) OrElse Not extension.StartsWith(".") Then Throw New ArgumentException("Extension must not be null, must also start with '.'", "extension")
        If String.IsNullOrEmpty(description) Then Throw New ArgumentException("description must not be null", "description")

        'Allow nothing to be passed for the icon file
        Dim iconFile As FileInfo = Nothing
        If iconPath IsNot Nothing Then
            iconFile = New FileInfo(iconPath)
            If Not iconFile.Exists Then Throw New ArgumentException("Icon file does not exist", "iconPath")
        End If

        Dim applicationFile As New FileInfo(applicationPath)
        If Not applicationFile.Exists Then Throw New ArgumentException("Application file does not exist", "applicationFile")

        'Create .extension value
        My.Computer.Registry.ClassesRoot.CreateSubKey(extension).SetValue("", name, Microsoft.Win32.RegistryValueKind.String)

        'Create filename value
        My.Computer.Registry.ClassesRoot.CreateSubKey((name & "\shell\open\command")).SetValue("", (applicationFile.FullName & " ""%l"" "), Microsoft.Win32.RegistryValueKind.String)

        'Set the description for the file name
        My.Computer.Registry.ClassesRoot.CreateSubKey(name).SetValue("", description)

        'Associate an icon if we were passed one
        If iconFile IsNot Nothing Then _
            My.Computer.Registry.ClassesRoot.CreateSubKey((name & "\DefaultIcon")).SetValue("", iconFile.FullName, Microsoft.Win32.RegistryValueKind.String)

    End Sub

Open in new window


2.- Catch the name of the file that open the project.
        If My.Application.CommandLineArgs.Count > 0 Then
            MessageBox.Show(My.Application.CommandLineArgs(0))
           ' If there is args the program will assume that it is opened by some of their files.
        Else
           ' If there is no args the program will assume that it is opened by the usual way.
        End If

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question