Am on Windows 8
I have a visual basic 2010 express application that plays mp3 files. It has a button which opens an openfiledialog box to select the mp3 you want to play. However I have also set my vb app to be the default opener of mp3 files. When I double click any mp3 it opens my vb app. But as yet I have no way to tell the vb app the name and path of the mp3 file which started it. The app just opens but does not play the mp3.
I need a way to get the vb app to get the filename and path of the mp3 so the player will play it. As far as I know the mp3 file is considered the parent of the vb app because it caused it to start.
I found this article which gave a little help, but I still got some weird public member boolean error which blew me away!
https://anoriginalidea.wordpress.com/2010/03/01/getting-the-parent-process-in-vb-net/
Thanks if you can help in any way.
If you've properly set up your file association, there's no need to muck around with process names. (Besides, the process starting your app would be Windows Explorer, because it's what handles double-clicks on a file and launches the associated app, so getting the process name wouldn't help you.) The filename is passed as a command-line parameter to your application, so you can retrieve it from there.
You can do so with Environment.GetCommandLineArgs()
, which returns an array containing all of the command line arguments passed to your app. The first element of the array (index 0) is the full path and filename of your application, the item at index 1 is the first argument passed (which should be your .mp3 name), etc.
Dim TheFileName As String
Dim Vars As String()
Vars = Environment.GetCommandLineArgs
If Vars.Length > 1 Then
TheFileName = Environment.GetCommandLineArgs(1)
Me.Text = TheFileName ' Just for demonstration
End If
If you haven't properly set up your file association so that this will work, you need to do so.