Solved

Startmenu pinned Items VBS Script

Posted on 2013-12-23
7
1,066 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

920 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

17 Experts available now in Live!

Get 1:1 Help Now