Add toolbar to taskbar using a script in Windows 7

Is there a way to use PS or VBS to run a script to add a folder to the taskbar using the toolbar properties.  I would like to add a folder under the start menu to the toolbar automatically.  We want to deploy this to all machines in the environment, however I don't want it to mess up other toolbars that are enabled on customer machines if applicable.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Another approach would be to create a shortcut to this folder e.g. within the Start Menu and then pin this shortcut to the taskbar.
Create a shortcut e.g. named Accessories in directory
"C:\ProgramData\Microsoft\Windows\Start Menu\Programs"
pointing to
C:\Windows\explorer.exe /e,"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories"

and then use the following VBS script to pin this shortcut to the taskbar.

The location of the shortcut, the name Accessories and the directory where it's pointing to should of course be changed to what you need.

'* Pin Shortcuts
Const PinTask = "Pin to Taskbar"
Const PinStart = "Pin to Start Menu"
Const UnpTask = "Unpin from Taskbar"
Const UnpStart = "Unpin from Start Menu"

Dim fso, objShell, strShortcut

Set fso = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application")

' Pin shortcut to taskbar
strShortcut = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories.lnk"
call PinItem(strShortcut, PinTask)

Set objShell = Nothing
Set fso = Nothing

Wscript.quit 0
' --------  SUBS  --------
Sub PinItem(sShortcut, sPinType)
  Dim sFolderPath, sFileName
  Dim objFolder, objFolderItem, colVerbs, objVerb

  If fso.FileExists(sShortcut) = False Then
    Exit Sub
  End If

  sFolderPath = fso.GetParentFolderName(sShortcut)
  sFileName = fso.GetFileName(sShortcut)

  Set objFolder = objShell.Namespace(sFolderPath)
  Set objFolderItem = objFolder.ParseName(sFileName)
  Set colVerbs = objFolderItem.Verbs
  For Each objVerb in colVerbs
    If Replace(, "&", "") = sPinType Then objVerb.DoIt

  Set colVerbs = Nothing
  Set objFolderItem = Nothing
  Set objFolder = Nothing
End Sub

Open in new window

mystikal1000Author Commented:
Zalazar - thanks for the effort, but really just need the toolbar, a pin shortcut will not work from a customer perspective.  I guess there is no PS or VBS script to do this?
I understand.
So far I could not find any PowerShell, VBS script or other code for this.
The settings are stored in the registry in REG_BINARY values which makes it difficult.
Check Out How Miercom Evaluates Wi-Fi Security!

It's not just about Wi-Fi connectivity anymore. A wireless security breach can cost your business large amounts of time, trouble, and expense. Plus, hear first-hand from Miercom on how WatchGuard's Wi-Fi security stacks up against the competition plus a LIVE demo!

It seems that Microsoft deliberately did not give access to these functions as it prefers only the user to change those.
Probably the only solution left is then to execute the task as if you where the user.
I have created an AutoIt script that does this.
It temporary blocks the keyboard/mouse input for the user so the script will not be interrupted.
IMPORTANT: The script needs to run with Administrative permissions so "Run as Administrator".
This is necessary for the BlockInput function.

You can download AutoIt from this location.

Download the zip version.
"AutoIt– Self Extracting Archive (for those who don’t like/want an installer)(includes x86 and x64 components and Aut2Exe and AutoItX)"
Open the zip and extract all files to a directory, preferably one without spaces.
E.g. C:\Programs\AutoIt\
Save the script below to a file and name it "Toolbar.au3" and place it in the same directory.

Now compile the script to an executable.
Startup .\install\Aut2Exe\Aut2exe_x64.exe if you are running a 64-bit OS
or Aut2exe.exe if you are running a 32-bit OS.

At the "Source (AutoIt .au3) textbox browse and select the "Toolbar.au3" script.
Select as Destination: .exe
Select "Compile for System: x64" if your Windows 7 clients are x64.
Click Convert.
An executable called  Toolbar.exe  will be created in the same directory as the script.

Now open a command prompt (cmd.exe) with Administrative permissions (Run as Administrator).
Toolbar.exe <directory for the toolbar>
Toolbar.exe "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Accessories"

Open in new window

Good luck.


Dim $strToolbarFolder, $oPosition

If UBound($CmdLine) <> 2 Then
  Exit 1

$strToolbarFolder = $CmdLine[1]

; Disable user input from the mouse and keyboard
ControlFocus("[CLASS:Shell_TrayWnd]", "", "[CLASSNN:ReBarWindow321]")

; Right click on the taskbar
$oPosition = ControlGetPos("[CLASS:Shell_TrayWnd]", "", "[CLASSNN:ReBarWindow321]")
ControlFocus("[CLASS:Shell_TrayWnd]", "", "[CLASSNN:ReBarWindow321]")
ControlClick("[CLASS:Shell_TrayWnd]", "", "[CLASSNN:ReBarWindow321]", "secondary", 1, $oPosition[2], $oPosition[3])

; Sleep and send T to select the Toolbar and N for "New toolbar..."

; Wait for the "New Toolbar - Choose a folder" window
If Not WinWaitActive("New Toolbar - Choose a folder", "", 3) Then
  Exit 1

; Lower send delays to speed up typing
Opt("SendKeyDelay", 1)
Opt("SendKeyDownDelay", 1)

; Type the name of the folder for the new toolbar

; Set send delays to default values again
Opt("SendKeyDelay", 5)
Opt("SendKeyDownDelay", 5)

; Go to the folder and select the "Select Folder" button

; Enable user input from the mouse and keyboard

Exit 0

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mystikal1000Author Commented:
This is exactly what I am looking for!!!  Thank you very much, you deserve 1000 points!
Very good that it's what you were looking for.
Appreciated to hear that, thank you very much too.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.