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.
LVL 1
mystikal1000Asked:
Who is Participating?
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.

zalazarCommented:
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(objVerb.name, "&", "") = sPinType Then objVerb.DoIt
  Next

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

Open in new window

0
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?
0
zalazarCommented:
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.
0
ON-DEMAND: 10 Easy Ways to Lose a Password

Learn about the methods that hackers use to lift real, working credentials from even the most security-savvy employees in this on-demand webinar. We cover the importance of multi-factor authentication and how these solutions can better protect your business!

zalazarCommented:
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.
https://www.autoitscript.com/site/autoit/downloads/

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>
E.g.
Toolbar.exe "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Accessories"

Open in new window


Good luck.

#NoTrayIcon
#RequireAdmin

Dim $strToolbarFolder, $oPosition

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

$strToolbarFolder = $CmdLine[1]

; Disable user input from the mouse and keyboard
BlockInput(1)
Sleep(500)
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..."
Send("T")
Send("{RIGHT}")
Sleep(500)
Send("N")

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

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

; Type the name of the folder for the new toolbar
Send($strToolbarFolder)

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

; Go to the folder and select the "Select Folder" button
Send("{ENTER}")
Sleep(500)
Send("{Tab}{ENTER}")

; Enable user input from the mouse and keyboard
BlockInput(0)

Exit 0

Open in new window

0

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!
0
zalazarCommented:
Very good that it's what you were looking for.
Appreciated to hear that, thank you very much too.
0
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
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.