Jump to content

Windows New File Context Menu Editor


gaxar77
 Share

Recommended Posts

This is a simple application I wrote that let's you modify the new file context menu. You can add and remove file types based on their extension. It shows a list of all the file types that are in the new menu based on their extension, and you can add and remove file types.

; Windows New File Context Menu Editor
; Author: gaxar77

#include "GuiConstants.au3"
#include "GuiListBox.au3"

Func _RegExistKey($sKeyname)
    RegEnumVal ($sKeyname, 1)
    Return (@error <= 0)
 EndFunc

 Func ShellNewKeyName($ext)
    Return "HKEY_CLASSES_ROOT\" & $ext & "\ShellNew"
 EndFunc

Func MsgBoxCannotModifyRegistry()
   MsgBox(0, "Error", "Unable to modify registry.")
EndFunc

$gui = GUICreate("Windows New File Context Menu Editor", 465, 445)
GuiSetState(@SW_SHOW, $gui)

$fileTypesList = GUICtrlCreateList("", 10, 10, 400, 400)
$newFileTypeTextBox = GuiCtrlCreateInput("", 10, 415, 350, 20)
$newFileTypeButton = GuiCtrlCreateButton("Add", 365, 415, 45, 20)
$removeFileTypeButton = GuiCtrlCreateButton("Remove", 415, 10, 45, 20)

$keyIndex = 1
While True
   $keyName = RegEnumKey("HKEY_CLASSES_ROOT", $keyIndex)

   If @error <> 0 Then
      ExitLoop
   EndIf

   If StringLeft($keyName, 1) = "." Then
      If _RegExistKey(ShellNewKeyName($keyName)) Then
         _GuiCtrlListBox_AddString($fileTypesList, $keyName)
      EndIf
   EndIf

   $keyIndex += 1
WEnd

While True
   $msg = GuiGetMsg()

   Switch $msg
      Case $GUI_EVENT_CLOSE
         ExitLoop

      Case $newFileTypeButton
         $ext = GuiCtrlRead($newFileTypeTextBox)
         If StringLen($ext) < 2 or StringLeft($ext, 1) <> "." Then
            MsgBox(0, "Error", "Invalid Extension")
         Else
            $newKeyName = ShellNewKeyName($ext)
            RegWrite($newKeyName)
            RegWrite($newKeyName, "NullFile", "REG_SZ", "")
            If _RegExistKey($newKeyName) Then
               If _GuiCtrlListBox_FindString($fileTypesList, $ext) = -1 Then
                  _GuiCtrlListBox_AddString($fileTypesList, $ext)
               EndIf
            Else
               MsgBoxCannotModifyRegistry()
            EndIf
         EndIf
      Case $removeFileTypeButton
         $ext = GuiCtrlRead($fileTypesList)
         If $ext <> "" Then
            $keyToRemove = ShellNewKeyName($ext)

            RegDelete($keyToRemove)

            If _RegExistKey($keyToRemove) Then
               MsgBoxCannotModifyRegistry()
            Else
               _GuiCtrlListBox_DeleteString($fileTypesList, _GuiCtrlListBox_FindString($fileTypesList, $ext))
            EndIf
         Else
            MsgBox(0, "Error", "No Item Selected")
         EndIf
   EndSwitch
WEnd


 

Edited by gaxar77
Link to comment
Share on other sites

Pretty neat. 

I can see some room for code cleanup and optimization (removing redundant code, create functions, etc.)

A cool improvement could be to add an export / import feature as well.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...