AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[Vista/Win7] Create a favorites bar for Explorer

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
fragman



Joined: 13 Oct 2009
Posts: 1193

PostPosted: Wed Oct 28, 2009 8:14 pm    Post subject: [Vista/Win7] Create a favorites bar for Explorer Reply with quote

Ever since I started using Win7, this command bar annoyed me, since it only takes space and doesn't provide much useful actions. However, I have now figured out a way how to add buttons that make explorer change location to favorite folders.
It is rather tedious, so I wrote a script to do this automagically!
It can add any (real) folder, and remove one or all buttons without much work, you just need to specify the paths.

For details, read http://www.winmatrix.com/forums/index.php?/topic/18832-adding-custom-buttons-to-the-explorer-command-bar/ for how to add buttons.

I simply have such a button execute the following script with a path as argument:

Code:
#NoEnv
#include %A_ScriptDir%\Lib\com.ahk

sPath=%1%
if (InStr(FileExist(sPath), "D") || SubStr(sPath,1,3)="::{")
{
   If (WinActive("ahk_class CabinetWClass"))
   {
      hwnd:=WinExist("A")
      If hWnd
     {
         sa := Com_CreateObject("Shell.Application")
         wins := sa.Windows
         loop % wins.count
            if((window:=wins.Item(A_Index-1)).Hwnd=hWnd)
               break
       DllCall("shell32\SHParseDisplayName", "Uint", COM_Unicode4Ansi(wPath,sPath) , "Uint", 0, "UintP", pidl, "Uint", 0, "Uint", 0)
       VarSetCapacity(sa,24,0), NumPut(DllCall("shell32\ILGetSize","Uint",pidl), NumPut(pidl, NumPut(1, NumPut(1,sa)),4))
         Window.Navigate2(COM_Parameter(0x2011,&sa))
     }
   }
}
else
   MsgBox, 0, Error, The path "%1%" doesn't exist


I compiled it, since I didn't look up yet how to start a script with the autohotkey.exe and pass parameters to it.

Here's the script that automatically adds and removes paths from the bar:
Code:
MsgBox, 4,, Would you like to add a button(yes) or remove one(no)?
IfMsgBox Yes
{
   path:=COM_CreateObject("Shell.Application").BrowseForFolder(0, "Enter Path to add as button", 0).Self.Path
   ;FileSelectFolder, path, ,3,Enter Path to add as button
   SplitPath, path , foldername
   if(foldername="")
      foldername:=path
   InputBox, foldername , Enter the title for the button, Enter the title for the button, , , , , , , , %foldername%]
   
   FileSelectFile, ahk_path , 1, %A_ScriptDir%\ChangeLocation.exe, Enter Path to ChangeLocation.exe , *.exe
   if( InStr(ahk_path,"\",0,strlen(ahk_path)))
      StringTrimRight, ahk_path, ahk_path,1
   if( InStr(path,"\",0,strlen(path)))
      StringTrimRight, path, path,1
   if( InStr(foldername,"\",0,strlen(foldername)))
      StringTrimRight, foldername, foldername,1
   ;InStr(Haystack, Needle [, CaseSensitive = false, StartingPos = 1])
      SomeCLSID:="{" . uuid(false) . "}"
      ;go into view folders (clsid)
      Loop, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes, 2, 0
      {
         ;figure out first free key number
         iterations:=0
         regkey:=A_LoopRegName
         Loop, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\%regkey%\TasksItemsSelected, 2, 0
         {
            iterations++
         }
         
         ;Write reg keys
         RegWrite, REG_EXPAND_SZ, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\%regkey%\TasksItemsSelected\%iterations%\%SomeCLSID%, Icon, `%SystemRoot`%\system32\SHELL32.dll`,0
         RegWrite, REG_SZ, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\%regkey%\TasksItemsSelected\%iterations%\%SomeCLSID%, InfoTip, %path%
         RegWrite, REG_SZ, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\%regkey%\TasksItemsSelected\%iterations%\%SomeCLSID%, Title, %foldername%
         RegWrite, REG_SZ, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\%regkey%\TasksItemsSelected\%iterations%\%SomeCLSID%\shell\InvokeTask\command, , "%ahk_path%" "%path%"
         
         ;Now the same for TasksNoItemsSelected
         iterations:=0
         ;figure out first free key number
         Loop, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\%regkey%\TasksNoItemsSelected, 2, 0
         {
            iterations++
         }
         
         ;Write reg keys
         RegWrite, REG_EXPAND_SZ, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\%regkey%\TasksNoItemsSelected\%iterations%\%SomeCLSID%, Icon, `%SystemRoot`%\system32\SHELL32.dll`,0
         RegWrite, REG_SZ, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\%regkey%\TasksNoItemsSelected\%iterations%\%SomeCLSID%, InfoTip, %path%
         RegWrite, REG_SZ, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\%regkey%\TasksNoItemsSelected\%iterations%\%SomeCLSID%, Title, %foldername%
         RegWrite, REG_SZ, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\%regkey%\TasksNoItemsSelected\%iterations%\%SomeCLSID%\shell\InvokeTask\command, , "%ahk_path%" "%path%"         
      }
}
IfMsgBox No
{
   MsgBox, 4,, Would you like to remove one button (yes) or remove all buttons(no) made by this script ?
   IfMsgBox Yes
   {
      path:=COM_CreateObject("Shell.Application").BrowseForFolder(0, "Enter Path which should be removed", 0).Self.Path
      if( InStr(ahk_path,"\",0,strlen(ahk_path)))
         StringTrimRight, ahk_path, ahk_path,1
      if( InStr(path,"\",0,strlen(path)))
         StringTrimRight, path, path,1
      if( InStr(foldername,"\",0,strlen(foldername)))
         StringTrimRight, foldername, foldername,1
      ;go into view folders (clsid)
      Loop, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes, 2, 0
      {         
         regkey:=A_LoopRegName
         found:=false
         Loop, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\%regkey%\TasksItemsSelected, 2, 0
         {
            numberfolder:=A_LoopRegName
            ;go into clsid folder
            Loop, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\%regkey%\TasksItemsSelected\%numberfolder%, 2, 0
            {
               RegRead, value, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\%regkey%\TasksItemsSelected\%numberfolder%\%A_LoopRegName%, InfoTip               
               if value = %path%
               {               
                  RegDelete, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\%regkey%\TasksItemsSelected\%numberfolder%
                  found:=true
                  break
               }
            }
         }
         Loop, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\%regkey%\TasksNoItemsSelected, 2, 0
         {
            numberfolder:=A_LoopRegName
            ;go into clsid folder
            Loop, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\%regkey%\TasksNoItemsSelected\%numberfolder%, 2, 0
            {
               RegRead, value, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\%regkey%\TasksNoItemsSelected\%numberfolder%\%A_LoopRegName%, InfoTip
               if value = %path%
               {                                 
                  RegDelete, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\%regkey%\TasksNoItemsSelected\%numberfolder%                  
                  found:=true
                  break
               }
            }
         }
         if(found=false) {
            msgbox Button not found!
            break
         }   
      }
   }
   IfMsgBox No
   {
      ;go into view folders (clsid)
      Loop, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes, 2, 0
      {         
         regkey:=A_LoopRegName
         ;go into number folder
         Loop, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\%regkey%\TasksItemsSelected, 2, 0
         {
            numberfolder:=A_LoopRegName
            ;go into clsid folder
            Loop, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\%regkey%\TasksItemsSelected\%numberfolder%, 2, 0
            {
               RegRead, value, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\%regkey%\TasksItemsSelected\%numberfolder%\%A_LoopRegName%\shell\InvokeTask\command
               
               if InStr(value, "ChangeLocation.exe")
               {               
                  RegDelete, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\%regkey%\TasksItemsSelected\%numberfolder%
               }
            }
         }
         Loop, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\%regkey%\TasksNoItemsSelected, 2, 0
         {
            numberfolder:=A_LoopRegName
            count:=0
            ;go into clsid folder
            Loop, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\%regkey%\TasksNoItemsSelected\%numberfolder%, 2, 0
            {
               RegRead, value, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\%regkey%\TasksNoItemsSelected\%numberfolder%\%A_LoopRegName%\shell\InvokeTask\command
               if InStr(value, "ChangeLocation.exe")
               {               
                  RegDelete, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\%regkey%\TasksNoItemsSelected\%numberfolder%
               }
            }
         }
      }
   }
}
return

uuid(c = false) { ; v1.1 - by Titan
   static n = 0, l, i
   f := A_FormatInteger, t := A_Now, s := "-"
   SetFormat, Integer, H
   t -= 1970, s
   t := (t . A_MSec) * 10000 + 122192928000000000
   If !i and c {
      Loop, HKLM, System\MountedDevices
      If i := A_LoopRegName
         Break
      StringGetPos, c, i, %s%, R2
      StringMid, i, i, c + 2, 17
   } Else {
      Random, x, 0x100, 0xfff
      Random, y, 0x10000, 0xfffff
      Random, z, 0x100000, 0xffffff
      x := 9 . SubStr(x, 3) . s . 1 . SubStr(y, 3) . SubStr(z, 3)
   } t += n += l = A_Now, l := A_Now
   SetFormat, Integer, %f%
   Return, SubStr(t, 10) . s . SubStr(t, 6, 4) . s . 1 . SubStr(t, 3, 3) . s . (c ? i : x)
}


Compiled versions of the two files:
http://www.autohotkey.net/~Fragman/FolderButtonManager.rar

Another idea would be to create a dynamic drive bar, that gets updated by a script when a drive is added/removed.

There's still one small problem, in folders where windows defines custom actions, the buttons aren't displayed. Removing the default buttons makes the folder buttons show up, but this is not quite what most people would want I suppose. If anyone has any ideas on this please post them.

I have tested this script quite a few times now, and it appears to be working without bugs, but if you want to be sure, please backup the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes registry branch.

Update:
Everythings working properly now, you can even add special folders now and assign custom button text. Also the script can remove all custom buttons at once.

Note: Current version of the script requires Autohotkey_L. Can easily be made working in normal ahk by replacing all occurences of
path:=COM_CreateObject(...) with
FileSelectFolder, path, ,3,Enter Path to add as button

But you won't be able to use special folders then.


Last edited by fragman on Tue Dec 01, 2009 11:11 pm; edited 4 times in total
Back to top
View user's profile Send private message
Night Hawk
Guest





PostPosted: Wed Nov 04, 2009 8:18 am    Post subject: Re: [Vista/Win7] Create a favorites bar for Explorer Reply with quote

There's a slight problem with the FolderButtonManager.exe file to work out at least for the 64bit Windows 7.

Quote:
Error at line 4.

The following variable name contains an illegal character.
"Self Path"

The program will exit.


The ChangeLocation.exe went on like a champ on the other hand and comes in quite useful for switching open windows back and forth between monitors!
Back to top
Lexikos



Joined: 17 Oct 2006
Posts: 7295
Location: Australia

PostPosted: Wed Nov 04, 2009 11:33 am    Post subject: Reply with quote

See the bottom of fragman's post, where it mentions the AutoHotkey_L requirement.
Back to top
View user's profile Send private message Visit poster's website
fragman



Joined: 13 Oct 2009
Posts: 1193

PostPosted: Wed Nov 04, 2009 3:19 pm    Post subject: Reply with quote

Ooops, looks like I compiled the exe incorrectly.
Can I replace the normal autohotkey.exe with the ahk_l one and compile it then?
You can still run the script with the autohotkey_l.exe though, that's what I'm doing locally.

Edit: I've updated the file with a fixed version that runs.
Edit2: Nicer version of ChangeLocation.exe that doesn't pop up autocomplete menu.
Back to top
View user's profile Send private message
Night Hawk
Guest





PostPosted: Thu Nov 05, 2009 11:52 pm    Post subject: Reply with quote

The one thing to know about the ChangeLocation.exe is that you need two screens for that one. The two buttons there are for moving from one to another with the other for seeing a window stretched across both monitors.

I still didn't see any result with the FolderButtonManager.exe however. This is on the 64bit Windows 7 to note.
Back to top
fragman



Joined: 13 Oct 2009
Posts: 1193

PostPosted: Sun Nov 08, 2009 5:22 pm    Post subject: Reply with quote

You might have to give yourself rights for the registry keys first. I don't know yet how to do that in AHK.

(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes)
Back to top
View user's profile Send private message
fragman



Joined: 13 Oct 2009
Posts: 1193

PostPosted: Tue Dec 01, 2009 11:12 pm    Post subject: Reply with quote

Updated code and files with a much more reliable method to set explorer address. I'm probably going to add command line switches to the manager script later on so that you can add and remove folders with hotkeys from other scripts.

Also to clarify things a bit, this has nothing to do with multimonitor support, Night Hawk confused this with a multimonitor tool that was running it seems.
Back to top
View user's profile Send private message
RobOtter



Joined: 30 Jan 2005
Posts: 133
Location: Darmstadt, Germany

PostPosted: Fri Dec 11, 2009 4:49 pm    Post subject: Reply with quote

fragman, nice work!

Do you know how create a drop down list instead of a single text entry? It would save much space in the command bar if one would add quite a bunch of folders.

Regards,
Rob
Back to top
View user's profile Send private message
RobOtter



Joined: 30 Jan 2005
Posts: 133
Location: Darmstadt, Germany

PostPosted: Tue Dec 15, 2009 1:15 am    Post subject: Reply with quote

Hi fragman,

today I saw your post at http://social.msdn.microsoft.com/Forums/en-US/windowsgeneraldevelopmentissues/thread/2ffef86f-8364-41fb-b7b7-4d0114ed0f01 - unfortunately, you didnīt receive an answer yet.

Playing with the registry, Iīve also found no way of mixing both methods of adding buttons. It came to my mind that it should be sufficient to add a new command in the CommandStore hive (if buttons in the FolderType branch are adde using the command name list) and add the newly created command to this list.
Commands in the CommandStore are also capable of creating drop down lists (have a look at Windows.organize/SubCommands) which would be great for a huge list of Favorite folders (my post above).

There are two problems right now:
- It seems impossible to add a button label (Key: MUIVerb) by using a simple string - only a reference to a dll resource is possible. Therefore, one canīt specify an arbitrary label at runtime - a static dll has to be created by the programmer before.
- No way to specify a program to execute directly, only way is to use command/DelegateExecute with cryptict GUID (see Windows.closewindow/command/DelegateExecute for example).

Any ideas anyone?

EDIT: Ok, this gets OT now. Iīll see what I can find out using the usenet.
Back to top
View user's profile Send private message
fragman



Joined: 13 Oct 2009
Posts: 1193

PostPosted: Wed Dec 23, 2009 12:50 pm    Post subject: Reply with quote

Let me know if you find anything, I'm highly interested in this too.

I think submenus can only be done via the command store hive, but I'm not sure.

Also, I would like to get those things working on "My Computer", as there seem to be premade entries which are probably stored in explorer itsself.
The organize menu and new folder seem non-removeable too?

One could maybe use the MUIVerbs by automating something like ressource hacker to change the strings inside a placeholder dll on runtime.

For executing programs, one could write a dll that provides a fixed number of GUIDs which then read a path from a config file to execute.

The script I'm currently working on (see http://www.autohotkey.com/forum/viewtopic.php?p=305224#305224 for a very outdated feature list) can store and recall paths on the numpad keys. I'm thinking to integrate this with the paths in the command bar, this would make it easy to customize them.
Back to top
View user's profile Send private message
fragman



Joined: 13 Oct 2009
Posts: 1193

PostPosted: Sat Jan 02, 2010 3:49 pm    Post subject: Reply with quote

My script now has integration with the command bar. You can store current path with ctrl+NumpadX and recall by clicking on command bar entry or pressing NumpadX. It's quite handy for quickly accessing often used folders, too bad they don't show up on 'My Computer'. Also it would be good to remove all other entries from that bar.
The only other possibility I could see would be to overlay your own GUI on that bar and do stuff there. This would allow for more control, but it might not be as neatly integrated.

Edit: I also integrated use of subinacl.exe for setting required permissions in registry.

Back to top
View user's profile Send private message
too lazy to log on
Guest





PostPosted: Sun Apr 11, 2010 11:48 pm    Post subject: Reply with quote

The download link doesn't work anymore.

can someone provide a mirror?


Thanks
Back to top
fragman



Joined: 13 Oct 2009
Posts: 1193

PostPosted: Sun Apr 11, 2010 11:50 pm    Post subject: Reply with quote

I suggest using my program [url=http://code.google.com/p/7plus/ 7plus], it has a nice integration of that feature. You can also check out its source to see how it's done.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group