Solved Pin Any Folder to Taskbar Auto Creation


dacrone

Well-known member
Guru
VIP
Local time
2:46 PM
Posts
4,598
OS
Windows 11 Pro
yes.. i know it can do the same with creating an explorer shortcut with the path. this is just for ease of automation. launch the exe and choose desired folder. it will create a .bat file in C:\Batch2ExplorerCustomLocation named the name of the chosen folder. it will create a shortcut to that .bat on your desktop with the target line modified to have cmd.exe /C before the target so that it will launch as a normal shortcut. after creating the shortcut it will open the Choose Icon gui from properties and load Shell32.dll. just choose an icon, then drag the shortcut from your desktop to the taskbar. (if i can find the keyboard method of pinning to taskbar that will work universally, i will update the script)

exe is attached in .zip. may have to allow on defender or other av
Code:
#Requires AutoHotkey v2.0
#SingleInstance Force

; Prompt user to select a folder
folder := DirSelect("Choose a folder to launch")
if !folder {
    MsgBox "No folder selected. Exiting."
    ExitApp
}

; Determine folder name or drive label
if RegExMatch(folder, "^[A-Z]:\\$") {
    ; It's a drive root like C:\ or D:\
    folderName := DriveGetLabel(SubStr(folder, 1, 2))
    if !folderName {
        ; If drive has no label, fall back to drive letter
        folderName := SubStr(folder, 1, 2)
    }
} else {
    ; Use last part of folder path
    folderName := StrSplit(RTrim(folder, "\"), "\")[-1]
}

batchDir := "C:\Batch2ExplorerCustomLocation"
if !DirExist(batchDir) {
    try DirCreate(batchDir)
    if !DirExist(batchDir) {
        MsgBox "Failed to create C:\Batch2ExplorerCustomLocation. Try running as administrator."
        ExitApp
    }
}

batchFile := batchDir "\" folderName ".bat"
if FileExist(batchFile)
    FileDelete(batchFile)

cmd := Format('start "" "{}"`n', folder)
FileAppend(cmd, batchFile)

shell := ComObject("WScript.Shell")

desktopPath := shell.SpecialFolders("Desktop")
shortcutPath := desktopPath "\" folderName ".lnk"
if FileExist(shortcutPath)
    FileDelete(shortcutPath)

shortcut := shell.CreateShortcut(shortcutPath)
shortcut.TargetPath := "cmd.exe"
shortcut.Arguments := Format('/C "{}"', batchFile)
shortcut.WorkingDirectory := batchDir
shortcut.IconLocation := "cmd.exe"
shortcut.WindowStyle := 7
shortcut.Save()

Run(Format('explorer.exe /select,"{}"', shortcutPath))
Sleep 2500

Send "!{Enter}"
Sleep 700
Send "!c"
Sleep 500

A_Clipboard := "C:\Windows\System32\shell32.dll"
Sleep 100
Send "^v"
Sleep 300
Send "{Enter}"

MsgBox "Choose Desired Icon. Then Drag Shortcut on Desktop to Taskbar to Pin It."
 

Attachments

My Computer

System One

  • OS
    Windows 11 Pro
Back
Top Bottom