seandisanti Posted January 17, 2006 Posted January 17, 2006 (edited) This is actually just the beginning of a much better script. i made this for a post in support, but i'm going to be making a GUI that lets you choose any extension, then see, add, edit, or remove any of the right click menus for that file type. I should have that one up tomorrow at the latest, but this one works to just add right click menu items to specific file types. There is no error correction in this script, so it assumes that you choose a file (with an extension), and that your strings are properly formatted, it just sends them as-is. when entering the command to be executed for the second input box, make sure to format it like the example. If you're calling a program or script that isn't in your %path%, make sure you include your full path and executable surrounded by quotes, followed by a %1 in it's own set of quotes, that passes the filename as a command line parameter to the program in the first part. There is a sample, but please understand that this DOES affect your registry. Use at your own risk.***edit***finished the gui etc, added more features... let me know what you think.***edit***added the ability to delete actions. helpful if you add actions as test, so you don't have to go into registry to remove them, or for when you uninstall programs and they don't remove their file associations.01/19/06 changes:i added the ability to change icons based on extension... also a note that i guess i didn't say earlier, whenever a change is made, the script wants to refresh itself so there is no bad data. the way that it refreshes itself is by hiding the gui, then re-running the compiled script, then closing the hidden gui. In order to use it correctly, you do need to (beta)compile the script. Otherwise the script will appear to hang when it says it's refreshing, and you'll have to close it via the systray icon.01/27/06 changes:removed styles from combo boxes to allow scrolling.expandcollapse popupGlobal $var2, $blah, $cmd, $ext #NoTrayIcon #include<GUIConstants.au3> opt("GUIOnEventMode", 1) $gui = GUICreate("Right Click", 500, 160) $exts = GUICtrlCreateCombo("Extensions", 10, 10, 70, 25) $cmds = GUICtrlCreateCombo("Actions", 90, 10, 130, 25) $ct = GUICtrlCreateEdit("", 10, 45, 410, 30, BitOR($ES_AUTOHSCROLL, $ES_AUTOVSCROLL)) $eb = GUICtrlCreateButton("Edit", 10, 85, 50) $sb = GUICtrlCreateButton("Save", 70, 85, 50) $cb = GUICtrlCreateButton("Cancel", 130, 85, 50) $na = GUICtrlCreateButton("New Action", 190, 85, 200) $da = GUICtrlCreateButton("Delete Action", 230, 10) $icon = GUICtrlCreateEdit("Icon", 320, 10, 100, -1, BitOR($ES_AUTOHSCROLL, $ES_AUTOVSCROLL)) $ci = GUICtrlCreateButton("Edit Icon", 430, 10, 60, 60) ControlDisable("Right Click", "", $eb) ControlDisable("Right Click", "", $ci) ControlDisable("Right Click", "", $icon) ControlDisable("Right Click", "", $na) ControlDisable("Right Click", "", $sb) ControlDisable("Right Click", "", $ct) ControlDisable("Right Click", "", $cb) ControlDisable("Right Click", "", $da) ControlDisable("Right Click", "", $cmds) GUICtrlSetOnEvent($exts, "EXTSelected") GUICtrlSetOnEvent($cmds, "CMDSelected") GUICtrlSetOnEvent($eb, "EditPushed") GUICtrlSetOnEvent($sb, "SavePushed") GUICtrlSetOnEvent($cb, "CancelPushed") GUICtrlSetOnEvent($na, "NewSelected") GUICtrlSetOnEvent($da, "DelSelected") GUICtrlSetOnEvent($ci, "CISelected") $i = 1 $cbt = "" While 1 $var = RegEnumKey("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\", $i) If $var = "" Then ExitLoop $cbt = $cbt & "|" & $var $i = $i + 1 WEnd GUICtrlSetData($exts, $cbt) ControlSetText("Right Click", "", $exts, "Extensions") GUISetState() GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") While 1 Sleep(100) WEnd Func CLOSEClicked() Exit EndFunc ;==>CLOSEClicked Func EXTSelected() $acbt = "" $ext = GUICtrlRead($exts) $var2 = RegEnumVal("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & $ext & "\OpenWithProgids", 1) $i = 1 GUICtrlSetData($icon, RegRead("HKEY_CLASSES_ROOT\" & $var2 & "\DefaultIcon\", "")) While 1 $var = RegEnumKey("HKEY_CLASSES_ROOT\" & $var2 & "\Shell\", $i) If $var = "" Then ExitLoop $acbt = $acbt & "|" & $var $i = $i + 1 WEnd GUICtrlSetData($cmds, $acbt) ControlSetText("Right Click", "", $cmds, "Actions") ControlEnable("Right Click", "", $cmds) ControlEnable("Right Click", "", $ci) ControlEnable("Right Click", "", $na) EndFunc ;==>EXTSelected Func CMDSelected() $cmd = GUICtrlRead($cmds) $blah = RegRead("HKEY_CLASSES_ROOT\" & $var2 & "\Shell\" & $cmd & "\Command\", "") GUICtrlSetData($ct, $blah) ControlEnable("Right Click", "", $eb) ControlEnable("Right Click", "", $da) EndFunc ;==>CMDSelected Func EditPushed() ControlEnable("Right Click", "", $ct) ControlEnable("Right Click", "", $cb) ControlDisable("Right Click", "", $eb) ControlEnable("Right Click", "", $sb) ControlDisable("Right Click", "", $cmds) ControlDisable("Right Click", "", $exts) EndFunc ;==>EditPushed Func SavePushed() $save = RegWrite("HKEY_CLASSES_ROOT\" & $var2 & "\Shell\" & $cmd & "\Command\", "", "REG_SZ", GUICtrlRead($ct)) If $save Then MsgBox(0, "Success", "Registry updated. Window must be refreshed") WinSetState("Right Click", "", @SW_HIDE) Run(@ScriptName) WinWaitActive("Right Click") Exit EndIf EndFunc ;==>SavePushed Func CancelPushed() ControlSetText("Right Click", "", $ct, "") ControlEnable("Right Click", "", $cmds) ControlEnable("Right Click", "", $exts) ControlDisable("Right Click", "", $eb) ControlDisable("Right Click", "", $sb) ControlDisable("Right Click", "", $cb) EndFunc ;==>CancelPushed Func NewSelected() $actionname = InputBox("New Action Name", "Enter a name for your new action to be added for files with the extension " & $ext) ControlSetText($gui, "", $cmds, $actionname) ControlEnable("Right Click", "", $ct) ControlEnable("Right Click", "", $cb) ControlEnable("Right Click", "", $sb) ControlDisable("Right Click", "", $na) $cmd = $actionname EndFunc ;==>NewSelected Func DelSelected() $confirm = MsgBox(4, "Delete Action", "Are you sure you want to permanently delete the " & GUICtrlRead($cmds) & " action?") If $confirm = 6 Then $del = RegDelete("HKEY_CLASSES_ROOT\" & $var2 & "\Shell\" & $cmd) If $del Then MsgBox(0, "Action Deleted", "The " & $cmd & " action will no longer appear when you right click on " & GUICtrlRead($exts) & " files. The window must be refreshed") WinSetState("Right Click", "", @SW_HIDE) Run(@ScriptName) WinWaitActive("Right Click") Exit EndIf EndIf EndFunc ;==>DelSelected Func CISelected() $newicon = FileOpenDialog("Choose new icon", "C:\", "All Files(*.*)") If Not @error Then $ni = RegWrite("HKEY_CLASSES_ROOT\" & $var2 & "\DefaultIcon\", "", "REG_SZ", $newicon) If $ni Then MsgBox(0, "Icon Changed", "The default icon for " & GUICtrlRead($exts) & " files has been changed. This window must be refreshed") WinSetState("Right Click", "", @SW_HIDE) Run(@ScriptName) WinWaitActive("Right Click") Exit EndIf EndIf EndFunc Edited January 27, 2006 by cameronsdad
Moderators SmOke_N Posted January 17, 2006 Moderators Posted January 17, 2006 Nice work Sean! Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
seandisanti Posted January 17, 2006 Author Posted January 17, 2006 Nice work Sean!thanks, i'm almost done with the beta for the full app...
seandisanti Posted January 17, 2006 Author Posted January 17, 2006 thanks, i'm almost done with the beta for the full app...here we go... let me know if you have any questions... expandcollapse popupGlobal $var2,$blah,$cmd,$ext #NoTrayIcon #include<GUIConstants.au3> Opt("GUIOnEventMode",1) $gui = GUICreate("Right Click",470,160) $exts = GUICtrlCreateCombo("Extensions",10,10,70,25,$CBS_DROPDOWN) $cmds = GUICtrlCreateCombo("Actions",90,10,130,25,$CBS_DROPDOWN) $ct = GUICtrlCreateEdit("",10,45,410,30,BitOR($ES_AUTOHSCROLL,$ES_AUTOVSCROLL)) $eb = GUICtrlCreateButton("Edit",10,85,50) $sb = GUICtrlCreateButton("Save",70,85,50) $cb = GUICtrlCreateButton("Cancel",130,85,50) $na = GUICtrlCreateButton("New Action",190,85,200) ControlDisable("Right Click","",$eb) ControlDisable("Right Click","",$na) ControlDisable("Right Click","",$sb) ControlDisable("Right Click","",$ct) ControlDisable("Right Click","",$cb) ControlDisable("Right Click","",$cmds) GUICtrlSetOnEvent($exts,"EXTSelected") GUICtrlSetOnEvent($cmds,"CMDSelected") GUICtrlSetOnEvent($eb,"EditPushed") GUICtrlSetOnEvent($sb,"SavePushed") GUICtrlSetOnEvent($cb,"CancelPushed") GUICtrlSetOnEvent($na,"NewSelected") $i = 1 $cbt = "" while 1 $var = RegEnumKey("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\",$i) ConsoleWrite(@LF & $var) If $var = "" Then ExitLoop $cbt = $cbt & "|" & $var $i = $i + 1 WEnd GUICtrlSetData($exts,$cbt) ControlSetText("Right Click","",$exts,"Extensions") GUISetState() GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") While 1 Sleep(100) WEnd Func CLOSEClicked() Exit EndFunc Func EXTSelected() $acbt = "" $ext = GUICtrlRead($exts) $var2 = RegEnumVal("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & $ext & "\OpenWithProgids",1) $i = 1 While 1 $var = RegEnumKey("HKEY_CLASSES_ROOT\"& $var2 & "\Shell\",$i) If $var = "" Then ExitLoop $acbt = $acbt & "|" & $var $i = $i + 1 WEnd GUICtrlSetData($cmds,$acbt) ControlSetText("Right Click","",$cmds,"Actions") ControlEnable("Right Click","",$cmds) ControlEnable("Right Click","",$na) EndFunc Func CMDSelected() $cmd = GUICtrlRead($cmds) $blah = RegRead("HKEY_CLASSES_ROOT\"& $var2 & "\Shell\" & $cmd & "\Command\","") GUICtrlSetData($ct,$blah) ControlEnable("Right Click","",$eb) EndFunc Func EditPushed() ControlEnable("Right Click","",$ct) ControlEnable("Right Click","",$cb) ControlDisable("Right Click","",$eb) ControlEnable("Right Click","",$sb) ControlDisable("Right Click","",$cmds) ControlDisable("Right Click","",$exts) EndFunc Func SavePushed() $save = RegWrite("HKEY_CLASSES_ROOT\" & $var2 & "\Shell\" & $cmd & "\Command\","","REG_SZ",GUICtrlRead($ct)) If $save Then MsgBox(0,"Success","Registry updated. Window must be refreshed") WinSetState("Right Click","",@SW_HIDE) Run(@ScriptName) WinWaitActive("Right Click") Exit EndIf EndFunc Func CancelPushed() ControlSetText("Right Click","",$ct,"") ControlEnable("Right Click","",$cmds) ControlEnable("Right Click","",$exts) ControlDisable("Right Click","",$eb) ControlDisable("Right Click","",$sb) ControlDisable("Right Click","",$cb) EndFunc Func NewSelected() $actionname = InputBox("New Action Name","Enter a name for your new action to be added for files with the extension " & $ext) ControlSetText($gui,"",$cmds,$actionname) ControlEnable("Right Click","",$ct) ControlEnable("Right Click","",$cb) ControlEnable("Right Click","",$sb) ControlDisable("Right Click","",$na) $cmd = $actionname EndFunc
Valuater Posted January 17, 2006 Posted January 17, 2006 very nice!! just needs a couple of "user" cautions... so they dont create thier own mistakes for example Func EXTSelected() ControlSetText("Right Click","",$ct,"") and....... Func NewSelected() $actionname = InputBox("New Action Name","Enter a name for your new action to be added for files with the extension " & $ext) If $actionname = "" then Return just little stuff... and safety ideas good job cameronsdad!! 8)
seandisanti Posted January 17, 2006 Author Posted January 17, 2006 very nice!!just needs a couple of "user" cautions... so they dont create thier own mistakesfor exampleFunc EXTSelected() ControlSetText("Right Click","",$ct,"")and.......Func NewSelected() $actionname = InputBox("New Action Name","Enter a name for your new action to be added for files with the extension " & $ext) If $actionname = "" then Returnjust little stuff... and safety ideasgood job cameronsdad!!8)thanks, yeah i'm bad about error control, but i tried to make it almost fool proof by disabling controls that aren't needed whenever they're not needed. Your first example for instance, they can't select an extension at the same time that there is something in the $ct box... for the second, if they don't enter a name, it actually won't be able to write anything to the registry, so they'll just be sitting there where they can cancel or save to restore to default... good suggestions though, thanks for the feedback!
seandisanti Posted January 19, 2006 Author Posted January 19, 2006 added the ability to change icons for files based on extension. if you click the edit icon button, you'll get a file open dialog. browse to and select the new icon file, then the program will make the change in the registry and reload itself to update all data.
mumdigau Posted January 27, 2006 Posted January 27, 2006 (edited) Hi cameronsdad, looks very nice. Unfortunately I can't scroll the extension dropdown list. So it ends after 30 entries. Best regards mumdigau Edited January 27, 2006 by mumdigau
seandisanti Posted January 27, 2006 Author Posted January 27, 2006 Hi cameronsdad,looks very nice. Unfortunately I can't scroll the extension dropdown list. So it ends after 30 entries.Best regardsmumdigaui use my mouse wheel to scroll, but i'll fix that right now...
mumdigau Posted January 27, 2006 Posted January 27, 2006 i use my mouse wheel to scroll, but i'll fix that right now...That doesn't work for me either.mumdigau
seandisanti Posted January 28, 2006 Author Posted January 28, 2006 That doesn't work for me either.mumdigauuse the new code at the top of the thread, i've re-added the scroll bar by just removing the style
GaryFrost Posted January 28, 2006 Posted January 28, 2006 here's something you might want to look at also http://www.autoitscript.com/forum/index.php?showtopic=12057# SciTE for AutoItDirections for Submitting Standard UDFs  Don't argue with an idiot; people watching may not be able to tell the difference. Â
Adam1213 Posted January 28, 2006 Posted January 28, 2006 The entire thing is nice but I want to make a new extension, also have autoit code generated to do making one this way I could eailsy add it to a program IRC Client - 75 pages 3728 lines. Blob crumbler (game)Backup (drag to backup + cmd line)RS232
theguy0000 Posted January 28, 2006 Posted January 28, 2006 I agree with Adam...automatically generating AutoIt code would be cool The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN
seandisanti Posted January 29, 2006 Author Posted January 29, 2006 The entire thing is nice but I want to make a new extension, also have autoit code generated to do making one this way I could eailsy add it to a programthere's an add extension button there... i'm sorry maybe i'm misunderstanding?
TheSaint Posted October 4, 2008 Posted October 4, 2008 The original code didn't work for me - 2 endless loops. Here is my modified working version, as cameronsdad suggested I post! expandcollapse popupGlobal $var2,$blah,$cmd,$ext ;#NoTrayIcon #include<GUIConstants.au3> Opt("GUIOnEventMode",1) $gui = GUICreate("Right Click",470,160) $exts = GUICtrlCreateCombo("Extensions",10,10,70,25,$CBS_DROPDOWN) $cmds = GUICtrlCreateCombo("Actions",90,10,130,25,$CBS_DROPDOWN) $ct = GUICtrlCreateEdit("",10,45,410,30,BitOR($ES_AUTOHSCROLL,$ES_AUTOVSCROLL)) $eb = GUICtrlCreateButton("Edit",10,85,50) $sb = GUICtrlCreateButton("Save",70,85,50) $cb = GUICtrlCreateButton("Cancel",130,85,50) $na = GUICtrlCreateButton("New Action",190,85,200) ControlDisable("Right Click","",$eb) ControlDisable("Right Click","",$na) ControlDisable("Right Click","",$sb) ControlDisable("Right Click","",$ct) ControlDisable("Right Click","",$cb) ControlDisable("Right Click","",$cmds) GUICtrlSetOnEvent($exts,"EXTSelected") GUICtrlSetOnEvent($cmds,"CMDSelected") GUICtrlSetOnEvent($eb,"EditPushed") GUICtrlSetOnEvent($sb,"SavePushed") GUICtrlSetOnEvent($cb,"CancelPushed") GUICtrlSetOnEvent($na,"NewSelected") GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") $i = 1 $cbt = "" while 1 $var = RegEnumKey("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\",$i) If @error <> 0 Then ExitLoop ConsoleWrite(@LF & $var) If $var = "" Then ExitLoop $cbt = $cbt & "|" & $var $i = $i + 1 WEnd ;MsgBox(0, "$var", $var) GUICtrlSetData($exts,$cbt) ControlSetText("Right Click","",$exts,"Extensions") GUISetState(@SW_SHOW) ;GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") While 1 Sleep(100) WEnd Func CLOSEClicked() Exit EndFunc Func EXTSelected() $acbt = "" $ext = GUICtrlRead($exts) $var2 = RegEnumVal("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & $ext & "\OpenWithProgids",1) ;MsgBox(0, "$var2", $var2) $i = 1 While 1 $var = RegEnumKey("HKEY_CLASSES_ROOT\"& $var2 & "\Shell\",$i) If @error <> 0 Or $var = "" Then ExitLoop $acbt = $acbt & "|" & $var $i = $i + 1 WEnd ;MsgBox(0, "$var", $var) GUICtrlSetData($cmds,$acbt) ControlSetText("Right Click","",$cmds,"Actions") ControlEnable("Right Click","",$cmds) ControlEnable("Right Click","",$na) EndFunc Func CMDSelected() $cmd = GUICtrlRead($cmds) $blah = RegRead("HKEY_CLASSES_ROOT\"& $var2 & "\Shell\" & $cmd & "\Command\","") GUICtrlSetData($ct,$blah) ControlEnable("Right Click","",$eb) EndFunc Func EditPushed() ControlEnable("Right Click","",$ct) ControlEnable("Right Click","",$cb) ControlDisable("Right Click","",$eb) ControlEnable("Right Click","",$sb) ControlDisable("Right Click","",$cmds) ControlDisable("Right Click","",$exts) EndFunc Func SavePushed() $save = RegWrite("HKEY_CLASSES_ROOT\" & $var2 & "\Shell\" & $cmd & "\Command\","","REG_SZ",GUICtrlRead($ct)) If $save Then MsgBox(0,"Success","Registry updated. Window must be refreshed") WinSetState("Right Click","",@SW_HIDE) Run(@ScriptName) WinWaitActive("Right Click") Exit EndIf EndFunc Func CancelPushed() ControlSetText("Right Click","",$ct,"") ControlEnable("Right Click","",$cmds) ControlEnable("Right Click","",$exts) ControlDisable("Right Click","",$eb) ControlDisable("Right Click","",$sb) ControlDisable("Right Click","",$cb) EndFunc Func NewSelected() $actionname = InputBox("New Action Name","Enter a name for your new action to be added for files with the extension " & $ext) ControlSetText($gui,"",$cmds,$actionname) ControlEnable("Right Click","",$ct) ControlEnable("Right Click","",$cb) ControlEnable("Right Click","",$sb) ControlDisable("Right Click","",$na) $cmd = $actionname EndFunc Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)
Garp99HasSpoken Posted October 6, 2008 Posted October 6, 2008 (edited) Copy into Scite as is and tried to compile with latest version.X:\AutoIt Examples\RightClick2.au3(6,66) : WARNING: $CBS_DROPDOWN: possibly used before declaration.$exts = GUICtrlCreateCombo("Extensions",10,10,70,25,$CBS_DROPDOWN)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^X:\AutoIt Examples\RightClick2.au3(8,62) : WARNING: $ES_AUTOHSCROLL: possibly used before declaration.$ct = GUICtrlCreateEdit("",10,45,410,30,BitOR($ES_AUTOHSCROLL,~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^X:\AutoIt Examples\RightClick2.au3(8,78) : WARNING: $ES_AUTOVSCROLL: possibly used before declaration.$ct = GUICtrlCreateEdit("",10,45,410,30,BitOR($ES_AUTOHSCROLL,$ES_AUTOVSCROLL)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^X:\AutoIt Examples\RightClick2.au3(6,66) : ERROR: $CBS_DROPDOWN: undeclared global variable.$exts = GUICtrlCreateCombo("Extensions",10,10,70,25,$CBS_DROPDOWN)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^X:\AutoIt Examples\RightClick2.au3 - 1 error(s), 3 warning(s) Edited October 6, 2008 by Garp99HasSpoken
TheSaint Posted October 6, 2008 Posted October 6, 2008 Copy into Scite as is and tried to compile with latest version.Hi Garp99HasSpokenThis is a pretty old script (so I'm told), so you need to use an older compiler if you don't want to update it yourself ... it's not my project and it didn't really do what I was looking for, so my interest in it is minimal. That said, I used AutoIt v3.2.0.1 or v3.2.4.9 when I tested/fixed it. Hope that helps! Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now