AutoHotkey Community

It is currently May 27th, 2012, 12:29 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: October 28th, 2009, 9:14 pm 
Offline

Joined: October 13th, 2009, 10:09 pm
Posts: 1389
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.p ... mmand-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/Fold ... anager.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 December 2nd, 2009, 12:11 am, edited 4 times in total.

Report this post
Top
 Profile  
Reply with quote  
PostPosted: November 4th, 2009, 9:18 am 
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!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 4th, 2009, 12:33 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
See the bottom of fragman's post, where it mentions the AutoHotkey_L requirement.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 4th, 2009, 4:19 pm 
Offline

Joined: October 13th, 2009, 10:09 pm
Posts: 1389
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 6th, 2009, 12:52 am 
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 8th, 2009, 6:22 pm 
Offline

Joined: October 13th, 2009, 10:09 pm
Posts: 1389
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)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 2nd, 2009, 12:12 am 
Offline

Joined: October 13th, 2009, 10:09 pm
Posts: 1389
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 11th, 2009, 5:49 pm 
Offline

Joined: January 30th, 2005, 11:18 pm
Posts: 133
Location: Darmstadt, Germany
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 15th, 2009, 2:15 am 
Offline

Joined: January 30th, 2005, 11:18 pm
Posts: 133
Location: Darmstadt, Germany
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 23rd, 2009, 1:50 pm 
Offline

Joined: October 13th, 2009, 10:09 pm
Posts: 1389
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/viewtop ... 224#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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 2nd, 2010, 4:49 pm 
Offline

Joined: October 13th, 2009, 10:09 pm
Posts: 1389
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.

Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 12th, 2010, 12:48 am 
The download link doesn't work anymore.

can someone provide a mirror?


Thanks


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 12th, 2010, 12:50 am 
Offline

Joined: October 13th, 2009, 10:09 pm
Posts: 1389
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.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Cristi®, Google Feedfetcher, tidbit and 57 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group