dmcdivitt

I wrote a program to help with PHP files. I want three things: run in the browser, open in notepad for editing, and create a new PHP file. This should all happen from the Windows Explorer right-click menu. I've added stuff to the right-click menu many times for many things, which is no big deal. I never have been able to add an item to the "new" sub menu, however. The item "Create new php file" or whatever, does not appear. My code is pasted below. Please say what I'm leaving out. Thanks

Dim exe$ = My.Application.Info.DirectoryPath & "\" & My.Application.Info.AssemblyName & ".exe"

My.Computer.Registry.SetValue("HKEY_CLASSES_ROOT\.php\ShellNew", "NullFile", "")

Dim a$ = My.Computer.Registry.GetValue("HKEY_CLASSES_ROOT\.php", "", "")

If Len(a) = 0 Then

a = "phpfile"

My.Computer.Registry.SetValue("HKEY_CLASSES_ROOT\.php", "", "phpfile")

My.Computer.Registry.SetValue("HKEY_CLASSES_ROOT\phpfile", "", "PHP Web Document")

End If

My.Computer.Registry.SetValue("HKEY_CLASSES_ROOT\" & a & "\shell", "", "browser")

My.Computer.Registry.SetValue("HKEY_CLASSES_ROOT\" & a & "\shell\browser", "", "Open in Browser")

My.Computer.Registry.SetValue("HKEY_CLASSES_ROOT\" & a & "\shell\browser\command", "", """" & exe & """ ""%1""")

My.Computer.Registry.SetValue("HKEY_CLASSES_ROOT\" & a & "\shell\http", "", "Edit HTTP path")

My.Computer.Registry.SetValue("HKEY_CLASSES_ROOT\" & a & "\shell\http\command", "", """" & exe & """ ""%1"" /set")

My.Computer.Registry.SetValue("HKEY_CLASSES_ROOT\" & a & "\shell\notepad", "", "Open with notepad")

My.Computer.Registry.SetValue("HKEY_CLASSES_ROOT\" & a & "\shell\notepad\command", "", """" & exe & """ ""%1"" /notepad")

MsgBox("Functionality added to right click menu")

[HKEY_CLASSES_ROOT\.php]
@="phpfile"

[HKEY_CLASSES_ROOT\.php\ShellNew]
"NullFile"=""

[HKEY_CLASSES_ROOT\phpfile]
@="PHP Web Document"

[HKEY_CLASSES_ROOT\phpfile\shell]
@="browser"

[HKEY_CLASSES_ROOT\phpfile\shell\browser]
@="Open in Browser"

[HKEY_CLASSES_ROOT\phpfile\shell\browser\command]
@="\"C:\\David\\ASP\\VB\\Projects\\RunPHP\\RunPHP\\obj\\Release\\RunPHP.exe\" \"%1\""

[HKEY_CLASSES_ROOT\phpfile\shell\http]
@="Edit HTTP path"

[HKEY_CLASSES_ROOT\phpfile\shell\http\command]
@="\"C:\\David\\ASP\\VB\\Projects\\RunPHP\\RunPHP\\obj\\Release\\RunPHP.exe\" \"%1\" /set"

[HKEY_CLASSES_ROOT\phpfile\shell\notepad]
@="Open with notepad"

[HKEY_CLASSES_ROOT\phpfile\shell\notepad\command]
@="\"C:\\David\\ASP\\VB\\Projects\\RunPHP\\RunPHP\\obj\\Release\\RunPHP.exe\" \"%1\" /notepad"



Re: Visual Basic General cannot get "new" sub menu to work in Explorer

dmcdivitt

I found the problem. The "open" verb must exist for the file class. No documentation I've seen anywhere says that. If there is no "open" verb I simply write the same thing there as the "browser" verb. Doesn't matter which one. I want the "browser" verb to be the default, but an "open" verb must still be there. My code is updated as follows:

Dim exe$ = My.Application.Info.DirectoryPath & "\" & My.Application.Info.AssemblyName & ".exe"

dim a$ = My.Computer.Registry.GetValue("HKEY_CLASSES_ROOT\.php", "", "")

If Len(a) = 0 Then

a = "phpfile"

My.Computer.Registry.SetValue("HKEY_CLASSES_ROOT\.php", "", a)

End If

My.Computer.Registry.SetValue("HKEY_CLASSES_ROOT\.php\ShellNew", "NullFile", "")

My.Computer.Registry.SetValue("HKEY_CLASSES_ROOT\" & a, "", "PHP Web Document")

My.Computer.Registry.SetValue("HKEY_CLASSES_ROOT\" & a & "\shell", "", "browser")

My.Computer.Registry.SetValue("HKEY_CLASSES_ROOT\" & a & "\shell\browser", "", "Open in Browser")

My.Computer.Registry.SetValue("HKEY_CLASSES_ROOT\" & a & "\shell\browser\command", "", """" & exe & """ ""%1""")

My.Computer.Registry.SetValue("HKEY_CLASSES_ROOT\" & a & "\shell\http", "", "Edit HTTP path")

My.Computer.Registry.SetValue("HKEY_CLASSES_ROOT\" & a & "\shell\http\command", "", """" & exe & """ ""%1"" /set")

My.Computer.Registry.SetValue("HKEY_CLASSES_ROOT\" & a & "\shell\notepad", "", "Open with notepad")

My.Computer.Registry.SetValue("HKEY_CLASSES_ROOT\" & a & "\shell\notepad\command", "", """" & exe & """ ""%1"" /notepad")

If Len(My.Computer.Registry.GetValue("HKEY_CLASSES_ROOT\" & a & "\shell\open\command", "", "")) = 0 Then

My.Computer.Registry.SetValue("HKEY_CLASSES_ROOT\" & a & "\shell\open", "", "Open")

My.Computer.Registry.SetValue("HKEY_CLASSES_ROOT\" & a & "\shell\open\command", "", """" & exe & """ ""%1""")

End If

MsgBox("Functionality added to right click menu")

Exit Sub

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.php]
@="phpfile"

[HKEY_CLASSES_ROOT\.php\ShellNew]
"NullFile"=""

[HKEY_CLASSES_ROOT\phpfile]
@="PHP Web Document"

[HKEY_CLASSES_ROOT\phpfile\shell]
@="browser"

[HKEY_CLASSES_ROOT\phpfile\shell\browser]
@="Open in Browser"

[HKEY_CLASSES_ROOT\phpfile\shell\browser\command]
@="\"C:\\David\\ASP\\VB\\Projects\\RunPHP\\RunPHP\\obj\\Release\\RunPHP.exe\" \"%1\""

[HKEY_CLASSES_ROOT\phpfile\shell\http]
@="Edit HTTP path"

[HKEY_CLASSES_ROOT\phpfile\shell\http\command]
@="\"C:\\David\\ASP\\VB\\Projects\\RunPHP\\RunPHP\\obj\\Release\\RunPHP.exe\" \"%1\" /set"

[HKEY_CLASSES_ROOT\phpfile\shell\notepad]
@="Open with notepad"

[HKEY_CLASSES_ROOT\phpfile\shell\notepad\command]
@="\"C:\\David\\ASP\\VB\\Projects\\RunPHP\\RunPHP\\obj\\Release\\RunPHP.exe\" \"%1\" /notepad"

[HKEY_CLASSES_ROOT\phpfile\shell\open]
@="Open"

[HKEY_CLASSES_ROOT\phpfile\shell\open\command]
@="\"C:\\David\\ASP\\VB\\Projects\\RunPHP\\RunPHP\\obj\\Release\\RunPHP.exe\" \"%1\""