Solved

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

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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

617 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