Solved

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

Posted on 2014-12-09
1
203 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

791 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