Hello,

As my question asks above I want to be able to have office icons appear on the task bad once my sysprepped image and post instllations have been completed.  I found a ton of stuff using vb scripts but I have no idea where to place those.  I also found some things using the unattanded.xml doc made with the WAIK but it only allows three links and I am not sure what the syntax is.  I remember there used to be another way but I cannot find it via the google machine.  Can anyone help me out?  This is a windows 7 sysprepped image.

 

thanks - Scott

0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Answers

3

do it with the answerfile, much easier.

this is part of my answer file. I add firefox and chrome to the bar

  <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <CopyProfile>true</CopyProfile>
            <ShowWindowsLive>false</ShowWindowsLive>
            <TimeZone>Pacific Standard Time</TimeZone>
            <ProductKey>33PXH-7Y6KF-2VJC9-XBBR8-HVTHH</ProductKey>
            <TaskbarLinks>
                <Link0>%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs\Mozilla Firefox.lnk</Link0>
                <Link1>%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs\Google Chrome.lnk</Link1>
            </TaskbarLinks>
            <WindowsFeatures>
                <ShowInternetExplorer>true</ShowInternetExplorer>
                <ShowMediaCenter>true</ShowMediaCenter>
                <ShowWindowsMediaPlayer>true</ShowWindowsMediaPlayer>
            </WindowsFeatures>
        </component>

Answered 07/25/2013 by: SMal.tmcc
Red Belt

  • the path is where they currently are located. for windows7 %ALLUSERSPROFILE% is really c:\programdata\
  • I saw that before but I'm unaware of where the .lnk file is for word, excel, and outlook. (i.e. the path to each I would place in the answerfile)
    • are they on your start menu in a sub folder? If yes use explorer and go to C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Office
      • This content is currently hidden from public view.
        Reason: Removed by member request
        For more information, visit our FAQ's.
      • so word for me would be
        %ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs\Microsoft Office\Microsoft Word 2010.lnk
  • OK I gotcha - let me add that to my answerfile.. thanks!
  • So I added the taskbarlink to my answer file and it did nto work. Here is what it looks like for my windows 7 image:

    <TaskbarLinks>
    <Link0>%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs\Microsoft Office\Microsoft Word 2010.lnk</Link0>
    <Link1>%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs\Microsoft Office\Microsoft Excel 2010.lnk</Link1>
    <Link2>%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs\Microsoft Office\Microsoft Outlook 2010.lnk</Link2>
    </TaskbarLinks>
  • The unattend limits the amount to 3 links. I use a bat files that calls a vbs, check out the deployment guys blog.

    bat file....

    @echo off

    rem pin item to taskbar

    cscript.exe "%~dp0\PinItem.vbs" /item:"C:\Program Files\Microsoft Office\Office12\Outlook.exe" /taskbar

    TIMEOUT /T 30

    cscript.exe "%~dp0\PinItem.vbs" /item:"C:\Program Files\EPSON Projector\EasyMP Network Projection V2\EMP_NSC.exe" /taskbar

    TIMEOUT /T 30

    cscript.exe "%~dp0\PinItem.vbs" /item:"C:\Program Files\Mozilla Firefox\firefox.exe" /taskbar


    exit

    vbs file...

    ' Windows Script Host Sample Script
    '
    ' ------------------------------------------------------------------------
    ' Copyright (C) 2009 Microsoft Corporation
    '
    ' You have a royalty-free right to use, modify, reproduce and distribute
    ' the Sample Application Files (and/or any modified version) in any way
    ' you find useful, provided that you agree that Microsoft and the author
    ' have no warranty, obligations or liability for any Sample Application Files.
    ' ------------------------------------------------------------------------

    '********************************************************************
    '*
    '* File: PinItem.vbs
    '* Date: 03/04/2009
    '* Version: 1.0.2
    '*
    '* Main Function: VBScipt to pin an item to the Start Menu or Taskbar
    '*
    '* Usage: cscript PinItem.vbs /item:<path to exe>
    '* [/taskbar] [/?]
    '*
    '* Copyright (C) 2009 Microsoft Corporation
    '*
    '* Revisions:
    '*
    '* 1.0.0 - 04/03/2008 - Created.
    '* 1.0.1 - 03/02/2009 - Used Replace in PinItem function to remove "&"
    '* from verb.
    '* 1.0.2 - 03/04/2009 - Script name was PinToStartMenu.vbs. Added
    '* /taskbar switch to pin items to taskbar on
    '* Win7.
    '*
    '********************************************************************


    '*****************************************************************************
    '* Declare Variables
    '*****************************************************************************

    Option Explicit
    'On Error Resume Next

    Dim blnPinned
    Dim blnTaskbar

    Dim i
    Dim intOpMode

    Dim objWshShell
    Dim objFSO
    Dim objShell

    Dim strPath
    Dim strArguments
    Dim strOptionsMessage

    ' Define constants
    Const CONST_ERROR = 0
    Const CONST_WSCRIPT = 1
    Const CONST_CSCRIPT = 2
    Const CONST_SHOW_USAGE = 3
    Const CONST_PROCEED = 4
    Const CONST_STRING_NOT_FOUND = -1
    Const CONST_FOR_READING = 1
    Const CONST_FOR_WRITING = 2
    Const CONST_FOR_APPENDING = 8
    Const CONST_Success = 0
    Const CONST_Failure = 1

    Const TRISTATE_USE_DEFAULT = -2
    Const TRISTATE_TRUE = -1 'Open the file as Unicode.
    Const TRISTATE_FALSE = 0 'Open the file as ASCII.

    blnTaskbar = False

    '*****************************************************************************
    '* Create Objects
    '*****************************************************************************

    Set objWshShell = CreateObject("Wscript.Shell")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objShell = CreateObject("Shell.Application")


    '********************************************************************
    '* Check script host exe and parse command line
    '********************************************************************

    'Get the command line arguments
    For i = 0 to Wscript.arguments.count - 1
    ReDim Preserve arrArguments(i)
    arrArguments(i) = Wscript.arguments.item(i)
    Next

    'Check whether the script is run using CScript
    Select Case intChkProgram()
    Case CONST_CSCRIPT
    'Do Nothing
    Case CONST_WSCRIPT
    WScript.Echo "Please run this script using CScript." & vbCRLF & _
    "This can be achieved by" & vbCRLF & _
    "1. Using ""CScript MODIFYUSERS.vbs arguments"" for Windows 95/98 or" & VbCrLf & _
    "2. Changing the default Windows Scripting Host setting to CScript" & vbCRLF & _
    " using ""CScript //H:CScript //S"" and running the script using" & vbCRLF & _
    " ""MODIFYUSERS.vbs arguments"" for Windows NT."
    WScript.Quit
    Case Else
    WScript.Quit
    End Select

    'Parse the command line
    Err.Clear()
    intOpMode = intParseCmdLine(arrArguments, strPath, blnTaskbar, strOptionsMessage)

    If Err.Number Then
    Wscript.Echo "Error 0X" & CStr(Hex(Err.Number)) & " occurred in parsing the command line."
    If Err.Description <> "" Then
    Wscript.Echo "Error description: " & Err.Description & "."
    End If
    'WScript.quit
    End If

    Select Case intOpMode
    Case CONST_SHOW_USAGE
    Call ShowUsage()
    WScript.quit
    Case CONST_PROCEED
    'Do nothing.
    Case CONST_ERROR
    WScript.quit
    Case Else
    Wscript.Echo "Error occurred in passing parameters."
    End Select


    '********************************************************************
    '* Main Script
    '********************************************************************

    WScript.Echo strOptionsMessage

    blnPinned = PinItem(strPath, blnTaskbar)
    WScript.Echo "Item pinned: " & CStr(blnPinned)

    If blnPinned Then
    WScript.Quit(0)
    Else
    WScript.Quit(1)
    End If


    '********************************************************************
    '*
    '* Function intChkProgram()
    '*
    '* Purpose: Determines which program is used to run this script.
    '*
    '* Input: None
    '*
    '* Returns: intChkProgram is set to one of CONST_ERROR, CONST_WSCRIPT,
    '* and CONST_CSCRIPT.
    '*
    '********************************************************************
    Private Function intChkProgram()

    ON ERROR RESUME NEXT

    Dim i
    Dim j
    Dim strFullName
    Dim strCommand

    'strFullName should be something like C:\WINDOWS\COMMAND\CSCRIPT.EXE
    strFullName = WScript.FullName
    If Err.Number then
    Wscript.Echo "Error 0x" & CStr(Hex(Err.Number)) & " occurred."
    If Err.Description <> "" Then
    Wscript.Echo "Error description: " & Err.Description & "."
    End If
    intChkProgram = CONST_ERROR
    Exit Function
    End If

    i = InStr(1, strFullName, ".exe", 1)
    If i = 0 Then
    intChkProgram = CONST_ERROR
    Exit Function
    Else
    j = InStrRev(strFullName, "\", i, 1)
    If j = 0 Then
    intChkProgram = CONST_ERROR
    Exit Function
    Else
    strCommand = Mid(strFullName, j+1, i-j-1)
    Select Case LCase(strCommand)
    Case "cscript"
    intChkProgram = CONST_CSCRIPT
    Case "wscript"
    intChkProgram = CONST_WSCRIPT
    Case Else 'should never happen
    Wscript.Echo "An unexpected program is used to run this script."
    Wscript.Echo "Only CScript.Exe or WScript.Exe can be used to run this script."
    intChkProgram = CONST_ERROR
    End Select
    End If
    End If

    End Function


    '********************************************************************
    '*
    '* Function intParseCmdLine()
    '*
    '* Purpose: Parses the command line.
    '*
    '* Input: arrArguments An array containing input from the command line
    '*
    '* Input: strPath Path of exe to pin
    '* strOptionsMessage String containing options selected
    '*
    '* Returns: intParseCmdLine is set to one of CONST_ERROR, CONST_SHOW_USAGE,
    '* and CONST_PROCEED.
    '*
    '********************************************************************
    Private Function intParseCmdLine(arrArguments, strPath, blnTaskbar, strOptionsMessage)

    ON ERROR RESUME NEXT

    Dim i
    Dim strFlag
    Dim strSwitchValue

    strFlag = arrArguments(0)
    Err.Clear()

    'Help is needed
    If (strFlag = "") OR (strFlag="help") OR (strFlag="/h") OR (strFlag="\h") OR (strFlag="-h") _
    OR (strFlag = "\?") OR (strFlag = "/?") OR (strFlag = "?") OR (strFlag="h") Then
    intParseCmdLine = CONST_SHOW_USAGE
    Exit Function
    End If

    strOptionsMessage = strOptionsMessage & "" & VbCrLf
    strOptionsMessage = strOptionsMessage & WScript.ScriptName & VbCrLf
    strOptionsMessage = strOptionsMessage & "" & VbCrLf
    strOptionsMessage = strOptionsMessage & "Command Line Options:" & vbCrLf
    strOptionsMessage = strOptionsMessage & "=======================================" & VbCrLf

    For i = 0 to UBound(arrArguments)
    strFlag = Left(arrArguments(i), InStr(1, arrArguments(i), ":")-1)
    If Err.Number Then 'An error occurs if there is no : in the string
    Err.Clear
    Select Case LCase(arrArguments(i))
    Case "/q"
    blnQuiet = True
    strOptionsMessage = strOptionsMessage & "Supress Console Output: " & blnQuiet & VbCrLf
    Case "/taskbar"
    blnTaskbar = True
    strOptionsMessage = strOptionsMessage & "Pin to Taskbar instead of Start Menu: " & blnTaskbar & VbCrLf
    Case Else
    Wscript.Echo arrArguments(i) & " is not recognized as a valid input."
    intParseCmdLine = CONST_ERROR
    Exit Function
    End Select
    Else
    strSwitchValue = Right(arrArguments(i), Len(arrArguments(i))-(Len(strFlag)+1))
    Select Case LCase(strFlag)
    Case "/item"
    strPath = strSwitchValue
    strOptionsMessage = strOptionsMessage & "Item to pin to Start Menu or Taskbar: " & strPath & VbCrLf
    Case else
    Wscript.Echo "Invalid flag " & strFlag & "."
    Wscript.Echo "Please check the input and try again."
    intParseCmdLine = CONST_ERROR
    Exit Function
    End Select
    End If
    Next

    If (strPath = "") Then
    Wscript.Echo "The /item switch is required"
    Wscript.Echo "Please check the input and try again."
    intParseCmdLine = CONST_ERROR
    Exit Function
    End If

    intParseCmdLine = CONST_PROCEED

    End Function


    '********************************************************************
    '*
    '* Function PinItem()
    '*
    '* Purpose: Pin item to the Start Menu.
    '*
    '* Input: strlPath Path of exe to pin
    '* blnTaskbar Pin item to Taskbar instead of Start Menu if true
    '*
    '* Dependencies: objShell Shell.Application object
    '* objFSO File System object
    '*
    '* Returns: True if the shortcut is created, else false
    '*
    '********************************************************************
    Function PinItem(strlPath, blnTaskbar)
    On Error Resume Next

    Dim colVerbs
    Dim itemverb

    Dim objFolder
    Dim objFolderItem

    Dim strFolder
    Dim strFile

    If objFSO.FileExists(strlPath) Then
    '***** Do nothing, folder exists
    Else
    '***** Folder does not exist
    PinItem = False
    WScript.Echo "File to pin does not exist."
    WScript.Echo "Please check the input and try again."
    Exit Function
    End If

    strFolder = objFSO.GetParentFolderName(strlPath)
    strFile = objFSO.GetFileName(strlPath)

    WScript.Echo "Folder: " & strFolder
    WScript.Echo "File: " & strFile

    Err.Clear
    Set objFolder = objShell.Namespace(strFolder)
    Set objFolderItem = objFolder.ParseName(strFile)

    ' ***** InvokeVerb for this does not work on Vista/WS2008
    'objFolderItem.InvokeVerb("P&in to Start Menu")

    ' ***** This code works on Vista/WS2008
    Set colVerbs = objFolderItem.Verbs

    If blnTaskbar Then
    For each itemverb in objFolderItem.verbs
    If Replace(itemverb.name, "&", "") = "Pin to Taskbar" Then itemverb.DoIt
    Next
    Else
    For each itemverb in objFolderItem.verbs
    If Replace(itemverb.name, "&", "") = "Pin to Start Menu" Then itemverb.DoIt
    Next
    End If

    If Err.Number = 0 Then
    PinItem = True
    Else
    PinItem = False
    End If
    End Function


    '********************************************************************
    '*
    '* Sub ShowUsage()
    '*
    '* Purpose: Shows the correct usage to the user.
    '*
    '* Input: None
    '*
    '* Output: Help messages are displayed on screen.
    '*
    '********************************************************************
    Sub ShowUsage()
    WScript.Echo "This script is used to Pin items to the Start Menu or Taskbar."
    WScript.Echo ""
    WScript.Echo "Usage: cscript " & WScript.ScriptName & " [options]"
    WScript.Echo ""
    WScript.Echo "Options:"
    WScript.Echo ""
    WScript.Echo " /item:<PathName> Path of item to pin."
    WScript.Echo ""
    WScript.Echo " /taskbar (Optional) Pin to Taskbar instead of Start Menu."
    WScript.Echo ""
    WScript.Echo " /? (Optional) Displays this help text."
    WScript.Echo ""
    WScript.Echo ""
    WScript.Echo ""
    End Sub


    Good luck, this works well for my deployment with sccm and mdt.
    • Schweet thanks for sharing this!
Please log in to comment
3

I ran into this issue when deploying Windows 7 (x86) 3 years ago.  Having only a year's worth of experience with imaging, I couldn't figure out solution prior to finalizing the image so I used a completely different process.

 

I created a script to pin/unpin applications to the taskbar and/or startmenu that runs on first login.  I realize it may not be the most elegant solution, but satisfied our needs for the past 3 years.

 

I'm working on a Windows 7 (x64) refresh and I'll try to do it the 'proper' way, but I like the fact that this is completely customizable, allowing us to unlink/link anything at any time by just simply adjusting how we're calling the script.

 

 

 

-------BEGIN CODE

'==========================================================================
'
' NAME: PinUnpin.vbs
'
' AUTHOR: Julius / haxin / Phylum
' REVISION: 2
' DATE  : 3/22/2013
'
' COMMENT: Use this script to
'	pin applications to the taskbar or the startmenu
'	unpin applications from the taskbar or startmenu
'
'==========================================================================

Dim iArgCount


iArgCount = WScript.Arguments.Count
If (iArgCount <> 3) Then
	ShowUsage
End If


Dim sAction,sSMorTB,sFilePath

sAction = LCase(WScript.Arguments.Item(0))
sSMorTB = LCase(WScript.Arguments.Item(1))
sFilePath = LCase(WScript.Arguments.Item(2))


If (sAction <> "pin") And (sAction <> "unpin") Then
	WScript.Echo "Error: Invalid Action: '" & sAction & "'"
	ShowUsage
End If


If (sSMorTB <> "startmenu") And (sSMorTB <> "taskbar") Then
	WScript.Echo "Error: Invalid Location: '" & sSMorTB & "'"
	ShowUsage
End If


If (sAction = "pin") And (sSMorTB = "startmenu") Then PinToStartMenu sFilePath
If (sAction = "pin") And (sSMorTB = "taskbar") Then PinToTaskBar sFilePath
If (sAction = "unpin") And (sSMorTB = "startmenu") Then UnpinFromStartMenu sFilePath
If (sAction = "unpin") And (sSMorTB = "taskbar") Then UnpinFromTaskBar sFilePath


WScript.Quit

Sub ShowUsage
	WScript.Echo "Usage:  " & WScript.ScriptName & " [PIN|UNPIN] [STARTMENU|TASKBAR] File"
	WScript.Echo vbTab & WScript.ScriptName & " PIN startmenu C:\apps\tools\wmopener.exe"
	WScript.Echo vbTab & WScript.ScriptName & " unpin TASKBAR ""C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Mozilla Firefox.lnk"""
	WScript.Quit
End Sub


Sub PinToStartMenu(Required_Path_To_Item)
	Const CSIDL_COMMON_PROGRAMS = &H17 
	Const CSIDL_PROGRAMS = &H2 
 
	Dim s_oFSO, s_oShell, s_oAllUsersProgramsFolder
	Dim s_oFolder, s_oFolderItem, s_colVerbs, s_oVerb
	Dim s_FullItemPath, s_sItemFolder, s_sItemName, s_sAllUsersProgramsPath

	Set s_oFSO = CreateObject("Scripting.FileSystemObject")
	Set s_oShell = CreateObject("Shell.Application")

	s_FullItemPath = Required_Path_To_Item

	If Not (s_oFSO.FileExists(s_FullItemPath)) Then
		WScript.Echo "Error Pinning File '" & s_FullItemPath & "' to Start Menu: File Does Not Exist!"
		Exit Sub
	End If


	s_sItemFolder = s_oFSO.GetParentFolderName(s_FullItemPath)
	s_sItemName = s_oFSO.GetFileName(s_FullItemPath)


	Set s_oFolder = s_oShell.Namespace(s_sItemFolder) 
	Set s_oFolderItem = s_oFolder.ParseName(s_sItemName) 
	Set s_colVerbs = s_oFolderItem.Verbs 

	For Each s_oVerb in s_colVerbs 
		If Replace(s_oVerb.name, "&", "") = "Pin to Start Menu" Then
			'WScript.Echo "Pinning '" & s_FullItemPath & "' to Start Menu"
			s_oVerb.DoIt
		ElseIf Replace(s_oVerb.name, "&", "") = "Unpin from Start Menu" Then
			WScript.Echo "Error: Item '" & s_FullItemPath & "' is Already Pinned to Start Menu"
		End If
	Next

End Sub

 

Sub PinToTaskBar(Required_Path_To_Item)
	Const CSIDL_COMMON_PROGRAMS = &H17 
	Const CSIDL_PROGRAMS = &H2 
 
	Dim s_oFSO, s_oShell, s_oAllUsersProgramsFolder
	Dim s_oFolder, s_oFolderItem, s_colVerbs, s_oVerb
	Dim s_FullItemPath, s_sItemFolder, s_sItemName, s_sAllUsersProgramsPath

	Set s_oFSO = CreateObject("Scripting.FileSystemObject")
	Set s_oShell = CreateObject("Shell.Application")

	s_FullItemPath = Required_Path_To_Item
 
	If Not (s_oFSO.FileExists(s_FullItemPath)) Then
		WScript.Echo "Error Pinning File '" & s_FullItemPath & "' to TaskBar: File Does Not Exist!"
		Exit Sub
	End If


	s_sItemFolder = s_oFSO.GetParentFolderName(s_FullItemPath)
	s_sItemName = s_oFSO.GetFileName(s_FullItemPath)
 
	Set s_oFolder = s_oShell.Namespace(s_sItemFolder) 
	Set s_oFolderItem = s_oFolder.ParseName(s_sItemName) 
	Set s_colVerbs = s_oFolderItem.Verbs 


	For Each s_oVerb in s_colVerbs 
		If Replace(s_oVerb.name, "&", "") = "Pin to Taskbar" Then
			'WScript.Echo "Pinning '" & s_FullItemPath & "' to Taskbar"
			s_oVerb.DoIt
		ElseIf Replace(s_oVerb.name, "&", "") = "Unpin from Taskbar" Then
			WScript.Echo "Error: Item '" & s_FullItemPath & "' is Already Pinned to Taskbar"
		End if
	Next

End Sub


Sub UnpinFromStartMenu(Required_Path_To_Item)
	Const CSIDL_COMMON_PROGRAMS = &H17 
	Const CSIDL_PROGRAMS = &H2 

	Dim s_oFSO, s_oShell, s_oAllUsersProgramsFolder
	Dim s_oFolder, s_oFolderItem, s_colVerbs, s_oVerb
	Dim s_FullItemPath, s_sItemFolder, s_sItemName, s_sAllUsersProgramsPath

	Set s_oFSO = CreateObject("Scripting.FileSystemObject")
	Set s_oShell = CreateObject("Shell.Application")

	s_FullItemPath = Required_Path_To_Item

	If Not (s_oFSO.FileExists(s_FullItemPath)) Then
		WScript.Echo "Error Unpinning File '" & s_FullItemPath & "' From Start Menu: File Does Not Exist!"
		Exit Sub
	End If

	s_sItemFolder = s_oFSO.GetParentFolderName(s_FullItemPath)
	s_sItemName = s_oFSO.GetFileName(s_FullItemPath)

	Set s_oFolder = s_oShell.Namespace(s_sItemFolder) 
	Set s_oFolderItem = s_oFolder.ParseName(s_sItemName) 
	Set s_colVerbs = s_oFolderItem.Verbs 
 
	For Each s_oVerb in s_colVerbs 
		If Replace(s_oVerb.name, "&", "") = "Unpin from Start Menu" Then
			'WScript.Echo "Unpinning '" & s_FullItemPath & "' From Start Menu"
			s_oVerb.DoIt
		ElseIf Replace(s_oVerb.name, "&", "") = "Pin to Start Menu" Then
			WScript.Echo "Error: Item '" & s_FullItemPath & "' is Not Pinned to Start Menu"
		End if
	Next
End Sub

 
Sub UnpinFromTaskBar(Required_Path_To_Item)
	Const CSIDL_COMMON_PROGRAMS = &H17 
	Const CSIDL_PROGRAMS = &H2 
 
	Dim s_oFSO, s_oShell, s_oAllUsersProgramsFolder
	Dim s_oFolder, s_oFolderItem, s_colVerbs, s_oVerb
	Dim s_FullItemPath, s_sItemFolder, s_sItemName, s_sAllUsersProgramsPath
 
	Set s_oFSO = CreateObject("Scripting.FileSystemObject")
	Set s_oShell = CreateObject("Shell.Application")

	s_FullItemPath = Required_Path_To_Item

	If Not (s_oFSO.FileExists(s_FullItemPath)) Then
		WScript.Echo "Error Unpinning File '" & s_FullItemPath & "' from Taskbar: File Does Not Exist!"
		Exit Sub
	End If


	s_sItemFolder = s_oFSO.GetParentFolderName(s_FullItemPath)
	s_sItemName = s_oFSO.GetFileName(s_FullItemPath)


	Set s_oFolder = s_oShell.Namespace(s_sItemFolder) 
	Set s_oFolderItem = s_oFolder.ParseName(s_sItemName) 
	Set s_colVerbs = s_oFolderItem.Verbs 

	For Each s_oVerb in s_colVerbs 
		If Replace(s_oVerb.name, "&", "") = "Unpin from Taskbar" Then
			'WScript.Echo "Unpinning '" & s_FullItemPath & "' from Taskbar"
			s_oVerb.DoIt
		ElseIf Replace(s_oVerb.name, "&", "") = "Pin to Taskbar" Then
			WScript.Echo "Error: Item '" & s_FullItemPath & "' is Not Pinned to Taskbar"
		End if
	Next
End Sub

 

-------END CODE

 

The script is fairly flexible...

  - allows you to pin/unpin an exe

  - allows you to pin/unpin a .LNK

  - is not case sensitive for pin/unpin action or the taskbar/startmenu location (of course file path is not case sensitive either - just has to be a valid path)

  - verifies the file you want to pin/unpin actually exists before attempting the action

 

However, you cannot pin a file located on a network share.  The workaround for that would be to create a .lnk file locally that points to the file on the network share and link that.  (There's another trick too actually but I don't want to complicate things!)

 

You can call the script via:

cscript //nologo pinunpin.vbs [PIN | UNPIN] [Taskbar | Startmenu] File
cscript //nologo pinunpin.vbs pin taskbar C:\path\to\file.exe
cscript //nologo pinunpin.vbs unpin startmenu "C:\path\to\folder with spaces\to\file.lnk"

Unfortunately, I wrote this for me and not for others so there's no commenting and no error trapping.  You can easily fix the latter by surrounding the pin/unpin action with something like:

 

on error resume next
<pin/unpin action>
if (err.number<>0) then
	wscript.echo "Error: " & err.number & " (" & hex(err.number) & ") performing action.  Reason: ' & err.description
	err.clear
	on error goto 0
	exit sub
else
	wscript.echo "Successfully performed action (" & err.number & "/" & hex(err.number) & ")"
end if
on error goto 0

 

I hope you find this helpful.

 

Julius / haxin / Phylum

Answered 07/25/2013 by: haxin
Orange Senior Belt

  • egads... is there no easier way? I am new to .vbs scripts and while I am a smart guy and could figure it out I am about ready to bag this because I have spent a lot of time already. For starters where so I place the scripts before I sysprep? C:\windows\setup\scripts? Also not really sure where to modify your script with my path for my office links. Oh and I am using Kace2000 for imaging if anyone else is using it too and has a fancy pre/post install they like to share.

    Scott
    • Hi Scott

      First: The script is ready to use - no modification necessary to get it to work. Just copy the code, paste, save as .VBS and that's it.


      Second: The script conveniently includes usage instructions (how to properly call the script) to help make sure would-be users use it correctly. Just run it without anything like
      cscript //nologo pinunpin.vbs
      And you'll get some help on how to properly use it. I also provided some examples above on how to call the script to create your shortcuts. If that wasn't sufficient, here are some more examples:

      ' To pin Command to the taskbar
      cscript //nologo pinunpin.vbs pin taskbar c:\windows\system32\cmd.exe

      ' To pin notepad to the start menu
      cscript //nologo pinunpin.vbs pin startmenu c:\windows\system32\notepad.exe

      ' To pin Internet Explorer to the startmenu
      ' Windows x64
      cscript //nologo pinunpin.vbs pin startmenu "C:\Program Files (x86)\Internet Explorer\iexplore.exe"
      ' Windows x86
      cscript //nologo pinunpin.vbs pin startmenu "C:\Program Files (x86)\Internet Explorer\iexplore.exe"

      ' To unpin Explorer from the taskbar
      cscript //nologo pinunpin.vbs unpin taskbar c:\windows\explorer.exe


      If you have a shortcut (a .LNK) that already exists on the Desktop or in Start > All Programs, that you want to pin to the taskbar, you can do that too - for example:
      cscript //nologo pinunpin.vbs unpin taskbar "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\iTunes\iTunes.lnk"

      It really is that simple.

      If you have multiple/several shortcuts to link, I strongly encourage you create a batch file that calls the script for each of the shortcuts. That batch file is then what you would execute on a per user basis to pin things where you want them to be. Two example batch files follow:

      This will pin/unpin one shortcut at a time - takes a while to process
      @echo off
      rem runs one at a time
      cscript //nologo pinunpin.vbs pin taskbar Shortcut1
      cscript //nologo pinunpin.vbs pin startmenu Shortcut2
      cscript //nologo pinunpin.vbs pin taskbar Shortcut3
      ...
      cscript //nologo pinunpin.vbs pin startmenu ShortcutX

      This will try to pin all of them at the same time
      @echo off
      rem spawns a separate process running all at the same time
      start /w "PinUnpin Task" cscript //nologo pinunpin.vbs pin startmenu Shortcut1
      start /w "PinUnpin Task" cscript //nologo pinunpin.vbs pin taskbar Shortcut2
      start /w "PinUnpin Task" cscript //nologo pinunpin.vbs pin startmenu Shortcut3
      ...
      start /w "PinUnpin Task" cscript //nologo pinunpin.vbs pin taskbar ShortcutX

      Now, there may be potential drawbacks to the latter method so the former may be preferred and I recommend. (Note: I use the former but in theory the latter should work as well. the shortcut ordering in the taskbar and on the startmenu may vary and not be consistent as one thread will finish before the other. If you want consistency - use the former method)


      Third: Where you store any/all scripts you use as part of your sysprep, post-sysprep and/or imaging process is totally up to you. It could be something simple like C:\Apps\scripts, in C:\Program Files someplace or on a network share if you like. Again - that's your decision, and you would know best.

      As for calling the script, there are a variety of ways to do that, and so its up to you:
      It could be a GPO
      It could be a runonce key
      it could be Windows Active Setup
      It could be a run synchronous/asynchronous command in your sysprep XML.

      Only you can determine the most appropriate location. (For example, you may find that run synchronous/asynchronous commands don't work right but RunOnce does.) I personally use RunOnce, and I did that by editing the default user hive and adding the key there. (If you need guidance there, let me know.)


      Lastly: When I started in this position I had zero software packaging & imaging experience so I had to figure things out the hard way. It also didn't help that we didn't have an imaging/deployment solution like Wise, Kace, MDT, SCCM/SMS etc.. Instead we used Ghost to capture the image and WinPE + Ghost to deploy said image. Because there were post imaging steps that were required, I edited the Sysprep file to execute commands and call scripts to do my bidding. We still use this method today, although I'm working on implementing SCCM 2012 to handle all the things I've had to create scripts for.

      I hope this helps get you started on the right path. I know how difficult it can be when you're trying to accomplish a task under a deadline, and you feel like you have no place to turn. I would offer my email address to help, but I think its better, for those that come after us, to keep the conversation & advice here just in case they run into the same problems!

      Cheers & enjoy your weekend!

      Julius


      Resources:
      Windows Active Setup
      http://blogs.msdn.com/b/aruns_blog/archive/2011/11/02/10176957.aspx
      http://blogs.flexerasoftware.com/installtalk/2011/11/using-active-setup-to-repair-user-settings.html
      http://helgeklein.com/blog/2012/03/get-rid-of-active-setup/

      All Users RunOnce
      http://support.microsoft.com/kb/284193
      (its for earlier versions of Windows but still relevant save for paths)
Please log in to comment
0

Julius, can you post the vbs because when I copy it, I get all code on 1 line... :(

Answered 03/05/2014 by: kingskawn
Purple Belt

  • Hey there kingskawn

    Sorry for not responding sooner. I don't believe I received a notification of a comment to this thread.

    Yeah - that's a bummer. Not sure why the site does it like that. In fact, when I go back in to edit the code, it's all warped. Yuck!

    I'll try to remember to circle back (if need be) to link you to the code on Pastebin or my OneDrive.
Please log in to comment
Answer this question or Comment on this question for clarity