Solved

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

Posted on 2014-12-09
1
205 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

739 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