Vb Net - Adding extensions to explorers context menu
Adding extensions to explorers context menu
This program will add a menu to a specific files explorer context menu.
I’ve never seen a good piece of source code to do this with, so here is a nice basic example which can be modified to do what you wish:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim RegKey As String = “ShockwaveFlash.ShockwaveFlash\shell\Open With AE H-Studio\command”
Try
If Registry.ClassesRoot.OpenSubKey(RegKey).GetValue(“”) = “” Then
”If the key exists but is blank, creates the subkey
Registry.ClassesRoot.CreateSubKey(RegKey).SetValue(“”, (ControlChars.Quote & Application.ExecutablePath & ControlChars.Quote & ” %1″))
MessageBox.Show(“Explorer Context Entry Added for .swf Files”, “Registry entry added:”, MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
Exit Sub
Application.Exit()
End If
Catch ex As Exception
”If the key does not exist at all, OpenSubKey will error (No object refrence) and this will create the key
Registry.ClassesRoot.CreateSubKey(RegKey).SetValue(“”, (ControlChars.Quote & Application.ExecutablePath & ControlChars.Quote & ” %1″))
MessageBox.Show(“Explorer Context Entry Added for .swf Files”, “Registry entry added:”, MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
Exit Sub
Application.Exit()
End Try
End Sub
Then, you have to add in the actual code that checks which file is being selected:
If Command() = “” Then
”If there is no command parameters, exit program
Application.Exit()
Exit Sub
End If
”This gets the fileinfo for the selected file, and calls the LoadSWF Function
Dim _file As New FileInfo(Interaction.Command)
LoadSWF(_file.FullName)
Application.Exit()
That can be placed in the Form Load even too, and it calls the sub LoadSWF (the selected file)
Public Sub LoadSWF(ByVal _path As String)
”This is where you would add in your code to handle the file loading.
”Currently it just creates a message box with the files name
MessageBox.Show(“Loaded File: “ & _path, “Success:”, MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
End Sub
As you can see, its not that hard, and the code would be very easy to modify.
For example, to add a shell extension for a .exe file change RegKey to:
Dim RegKey As String = “exefile\shell\Open With Program Name\command”