Solved

Startmenu pinned Items VBS Script

Posted on 2013-12-23
7
1,056 Views
Last Modified: 2013-12-31
I have a vbs script that will add one app to the start menu as a pinned item, how do I add more than one?  It works fine, but need to add more.

I appreciate the help!
startmenu-pinned.vbs
0
Comment
Question by:mystikal1000
  • 3
  • 2
  • 2
7 Comments
 
LVL 6

Expert Comment

by:Bxoz
ID: 39736317
http://blogs.technet.com/b/deploymentguys/archive/2009/04/08/pin-items-to-the-start-menu-or-windows-7-taskbar-via-script.aspx

At the end of the article you will find a PinItem.zip file with PinItem.vbs file inside
You can Pin all the item you want with this single ligne
cscript PinItem.vbs /item:<path to exe>
0
 
LVL 1

Author Comment

by:mystikal1000
ID: 39736517
I see, but do you have to run the vbs multiple times to pin for each item?
0
 
LVL 6

Expert Comment

by:Bxoz
ID: 39736586
You can use an Array

Dim myArray(2)
myArray(0) = "C:\Program Files\Microsoft Office 15\root\office15\WINWORD.EXE"
myArray(1) = "C:\Program Files\Microsoft Office 15\root\office15\EXCEL.EXE"
myArray(2) = "C:\Program Files\Microsoft Office 15\root\office15\OUTLOOK.EXE"
For Each present In myArray
cscript PinItem.vbs /item:present
Next
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 68

Expert Comment

by:Qlemo
ID: 39739783
That script has a lot of noise for such a simple task ... And I don't think you can use CSCRIPT calls in VBS ;-). The general idea is ok, but I would do different:
Sub PinToStartMenu(objFolderItemlink)
  For Each objVerb in objFolderItem.Verbs 
    If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt 
  Next
End Sub

Const CSIDL_COMMON_PROGRAMS = &H17 
Const CSIDL_PROGRAMS = &H2 
Set objShell = CreateObject("Shell.Application") 

strAllUsersProgramsPath = objShell.NameSpace(CSIDL_COMMON_PROGRAMS).Self.Path 
Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Microsoft Office") 

PinToStartMenu objFolder.ParseName("Microsoft Word 2010.lnk")
PinToStartMenu objFolder.ParseName("Microsoft Excel 2010.lnk")
PinToStartMenu objFolder.ParseName("Microsoft Outlook 2010.lnk")

Open in new window

or
Const CSIDL_COMMON_PROGRAMS = &H17 
Const CSIDL_PROGRAMS = &H2 
Set objShell = CreateObject("Shell.Application") 

strAllUsersProgramsPath = objShell.NameSpace(CSIDL_COMMON_PROGRAMS).Self.Path 
Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Microsoft Office") 

For Each item in array("Word", "Excel", "Outlook")
  For Each objVerb in objFolder.ParseName("Microsoft " & item & " 2010.lnk").Verbs 
    If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt 
  Next
Next

Open in new window

or a mixture of both.
0
 
LVL 1

Author Comment

by:mystikal1000
ID: 39746753
Qlemo,

How do I add a different folder location other than Microsoft Office apps, what if I want to add more apps in different folder locations?
0
 
LVL 6

Assisted Solution

by:Bxoz
Bxoz earned 50 total points
ID: 39746843
Qlemo has right we can call cscript in VBS

So you can create a .bat file in the same directory of PinItem.vbs
in the .bat file

cscript PinItem.vbs /item:"C:\Program Files\Mozilla Firefox\firefox.exe"
cscript PinItem.vbs /item:%windir%\system32\calc.exe
cscript PinItem.vbs /item:"C:\Program Files\Microsoft Office 15\root\office15\WINWORD.EXE"
cscript PinItem.vbs /item:"C:\Program Files\Microsoft Office 15\root\office15\OUTLOOK.EXE"

your system has to be in English otherwise you have to change the verb in the PinItem.vbs
If Replace(itemverb.name, "&", "") = "Pin to Start Menu" Then itemverb.DoIt
0
 
LVL 68

Accepted Solution

by:
Qlemo earned 450 total points
ID: 39747751
We can expand the first code to simplify the task of having different folder locations:
Sub PinToStartMenu(strpath, strlink)
  For Each objVerb in objShell.Namespace(strpath).ParseName(strlink).Verbs 
    If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt 
  Next
End Sub

Const CSIDL_COMMON_PROGRAMS = &H17 
Const CSIDL_PROGRAMS = &H2 
Set objShell = CreateObject("Shell.Application") 

strAllUsersProgramsPath = objShell.NameSpace(CSIDL_COMMON_PROGRAMS).Self.Path 
Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Microsoft Office") 

PinToStartMenu strAllUsersProgramsPath & "\Microsoft Office", "Microsoft Word 2010.lnk"
PinToStartMenu strAllUsersProgramsPath & "\xyz", "XYZ.lnk"

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
In this Micro Tutorial viewers will learn how to use Boot Corrector from Paragon Rescue Kit Free to identify and fix the boot problems of Windows 7/8/2012R2 etc. As an example is used Windows 2012R2 which lost its active partition flag (often happen…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now