Question: I have this code that makes it so that all files with the ".whatever" extension open with my program:

```
If Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(".whatever\shell\open\command", True) Is Nothing Then
    Dim icotouse As String = Path.GetTempPath() & "\whatever.ico"
    My.Computer.Registry.ClassesRoot.CreateSubKey(".whatever").SetValue("", "whatever", Microsoft.Win32.RegistryValueKind.String)
    My.Computer.Registry.ClassesRoot.CreateSubKey("whatever\shell\open\command").SetValue("", Application.ExecutablePath, Microsoft.Win32.RegistryValueKind.String)
    My.Computer.Registry.ClassesRoot.CreateSubKey("whatever\DefaultIcon").SetValue("", icotouse)
End If

```

Now when the user double clicks the ".whatever" file, it will open in my program.

How do I get the directory of where the ".whatever" file was when I open it in my program? For example, user clicks a file on their desktop [C:\Users\Example\Desktop\file.whatever] and when they click it, it opens up in my program, and I can assign a variable name to that directory?

Answer: 
First of all you need to make Windows pass the path of the file to your program. This is done by adding `%1` to the `command` key's default value.

Change your code that creates the `command` key to this:

```
My.Computer.Registry.ClassesRoot.CreateSubKey("whatever\shell\open\command").SetValue("", Application.ExecutablePath & " %1", Microsoft.Win32.RegistryValueKind.String)

```

Secondly, to get the path of the file sent to your program, you'd use for example `Environment.GetCommandLineArgs()`.

Put this somewhere like in the `Form_Load` event:

```
Dim Arguments() As String = Environment.GetCommandLineArgs()

If Arguments.Length > 1 Then 'If there's more than one argument, it means that something (like a file) was passed to your application.

End If

```

Now, the `If`-statement checks if a parameter was sent to your application. To get the path of your file you'd simply put something like this inside it:

```
Dim FilePath As String = Arguments(1)
'Will give you for example: C:\Users\Example\Desktop\file.whatever

```

But if you want to get the file's directory, you can do the following below:

```
Dim FileDirectory As String = IO.Path.GetDirectoryName(FilePath)
'Will give you for example: C:\Users\Example\Desktop

```
You need to get the Command Line Arguments 

You can do that with something like this

```
Dim arguments As String() = Environment.GetCommandLineArgs()
Console.WriteLine("GetCommandLineArgs: {0}", String.Join(", ", arguments))

```

Also you might want to look at this MSDN link

<https://msdn.microsoft.com/en-us/library/system.environment.getcommandlineargs(v=vs.110).aspx>