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.