none
VBScript StartMenu & Taskbar pin help

    Întrebare

  • I am working on a script that will add shortcuts to users W7 startmenu and taskbar but need some help. It is working as expected, but I am finding it starts adding numbers to the shortcuts because there is already a shortcut there. So I decided to add a text file to users profile location on completion so it wouldn't run if this file was there. I am still finding shortcuts are continuing and it is not consistent enough.

    I now would like to delete appropriate shortcuts in the location prior to script running and prevent this issue but it is not working. Can someone take a look for me please?

    'StartMenu pinned location %AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned

    Option Explicit

    WScript.Sleep 5000

    'Declare constants
    Const CSIDL_COMMON_PROGRAMS = &H17
    Const CSIDL_PROGRAMS = &H2
    Const CSIDL_STARTMENU = &HB

    'Declare variables
    Dim objShell, objFSO
    Dim objCurrentUserStartFolder
    Dim strCurrentUserStartFolderPath
    Dim objAllUsersProgramsFolder
    Dim strAllUsersProgramsPath
    Dim objFolder
    Dim objFolderItem
    Dim colVerbs
    Dim objVerb
    Dim arrOfficeArray (2)
    Dim i
    Dim objFolderWMP
    Dim objFolderItemWMP
    Dim oshell
    Dim strAppdata
    Dim logfile

    'Initialize variables
    arrOfficeArray(0) = "Microsoft Outlook 2010.lnk"
    arrOfficeArray(1) = "Microsoft Word 2010.lnk"
    arrOfficeArray(2) = "Microsoft Excel 2010.lnk"

    Set objShell = CreateObject("Shell.Application")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objCurrentUserStartFolder = objShell.NameSpace (CSIDL_STARTMENU)
    strCurrentUserStartFolderPath = objCurrentUserStartFolder.Self.Path
    Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS)
    strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path
    Set oShell = CreateObject("WScript.Shell")
    strAppdata = oShell.ExpandEnvironmentStrings("%APPDATA%")

    'Unpin from taskbar - Windows Media Player
    Set objShell = CreateObject("Shell.Application")
    Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS)
    strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path
    Set objFolderWMP = objShell.Namespace(strAllUsersProgramsPath)
    Set objFolderItemWMP = objFolderWMP.ParseName("Windows Media Player.lnk")
    Set colVerbs = objFolderItemWMP.Verbs
    For Each objVerb in colVerbs
          If Replace(objVerb.name, "&", "") = "Unpin from Taskbar" Then objVerb.DoIt
    Next

    If objFSO.FileExists(strAppdata & "\flag.txt") Then
    Wscript.Quit
    Else

    'Pin to taskbar - Outlook
    Set objShell = CreateObject("Shell.Application")
    Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS)
    strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path
    Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Microsoft Office")

    objFSO.DeleteFile "%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft Outlook 2010*.lnk", True
    objFSO.DeleteFile "%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft Word 2010*.lnk", True
    objFSO.DeleteFile "%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft Excel 2010*.lnk", True

    For i = 0 To 0
     Set objFolderItem = objFolder.ParseName(arrOfficeArray(i))
     Set colVerbs = objFolderItem.Verbs
     For Each objVerb in colVerbs
         If Replace(objVerb.name, "&", "") = "Pin to Taskbar" Then objVerb.DoIt
     Next
    Next

    'Pin to Start Menu - Outlook, Word, Excel
    Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Microsoft Office")
    For i = 0 To 2
     Set objFolderItem = objFolder.ParseName(arrOfficeArray(i))
     Set colVerbs = objFolderItem.Verbs
     For Each objVerb in colVerbs
         If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt
     Next
    Next

    'Creates logfile in \\server\profiles\%username%\Application Data and AppData\Roaming
    Set logFile = objFSO.CreateTextFile(strAppdata & "\flag.txt", TRUE)
    logFile.WriteLine("Flag.")
    logFile.Close
    End If

    27 februarie 2012 10:07

Răspunsuri

Toate mesajele

  • Start here:

    http://blogs.technet.com/b/heyscriptingguy/archive/2004/11/11/can-i-pin-a-file-to-the-start-menu-by-using-a-script.aspx

    Using the verbs will prevent you from doing this twice.


    ¯\_(ツ)_/¯

    27 februarie 2012 16:51
  • Thank you.

    I tried a few things but had difficulty. Any chance someone can help?

    16 martie 2012 17:25
  • Thank you.

    I tried a few things but had difficulty. Any chance someone can help?

    We can't help you if you don't show us what you tried.


    ¯\_(ツ)_/¯

    16 martie 2012 17:54
  • Here it is. Highlighted in bold what I tried :

    'StartMenu pinned location %AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned

    Option Explicit

    WScript.Sleep 5000

    'Declare constants
    Const CSIDL_COMMON_PROGRAMS = &H17
    Const CSIDL_PROGRAMS = &H2
    Const CSIDL_STARTMENU = &HB

    'Declare variables
    Dim objShell, objFSO
    Dim objCurrentUserStartFolder
    Dim strCurrentUserStartFolderPath
    Dim objAllUsersProgramsFolder
    Dim strAllUsersProgramsPath
    Dim objFolder
    Dim objFolderItem
    Dim colVerbs
    Dim objVerb
    Dim arrOfficeArray (2)
    Dim i
    Dim objFolderWMP
    Dim objFolderItemWMP
    Dim oshell
    Dim strAppdata
    Dim logfile

    'Initialize variables
    arrOfficeArray(0) = "Microsoft Outlook 2010.lnk"
    arrOfficeArray(1) = "Microsoft Word 2010.lnk"
    arrOfficeArray(2) = "Microsoft Excel 2010.lnk"

    Set objShell = CreateObject("Shell.Application")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objCurrentUserStartFolder = objShell.NameSpace (CSIDL_STARTMENU)
    strCurrentUserStartFolderPath = objCurrentUserStartFolder.Self.Path
    Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS)
    strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path
    Set oShell = CreateObject("WScript.Shell")
    strAppdata = oShell.ExpandEnvironmentStrings("%APPDATA%")

    'Unpin from taskbar - Windows Media Player
    Set objShell = CreateObject("Shell.Application")
    Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS)
    strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path
    Set objFolderWMP = objShell.Namespace(strAllUsersProgramsPath)
    Set objFolderItemWMP = objFolderWMP.ParseName("Windows Media Player.lnk")
    Set colVerbs = objFolderItemWMP.Verbs
    For Each objVerb in colVerbs
          If Replace(objVerb.name, "&", "") = "Unpin from Taskbar" Then objVerb.DoIt
    Next

    If objFSO.FileExists(strAppdata & "\flag.txt") Then
    Wscript.Quit
    Else

    'Pin to taskbar - Outlook
    Set objShell = CreateObject("Shell.Application")
    Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS)
    strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path
    Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Microsoft Office")

    'objFolderItem.InvokeVerb("Unpin from Start Menu")

    'objFSO.DeleteFile "%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft Outlook 2010*.lnk", True
    'objFSO.DeleteFile "%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft Word 2010*.lnk", True
    'objFSO.DeleteFile "%AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu\Microsoft Excel 2010*.lnk", True


    For i = 0 To 0
     Set objFolderItem = objFolder.ParseName(arrOfficeArray(i))
     Set colVerbs = objFolderItem.Verbs
     For Each objVerb in colVerbs
         If Replace(objVerb.name, "&", "") = "Unpin from Taskbar" Then objVerb.DoIt
     Next
    Next

    For i = 0 To 0
     Set objFolderItem = objFolder.ParseName(arrOfficeArray(i))
     Set colVerbs = objFolderItem.Verbs
     For Each objVerb in colVerbs
         If Replace(objVerb.name, "&", "") = "Pin to Taskbar" Then objVerb.DoIt
     Next
    Next


    'Pin to Start Menu - Outlook, Word, Excel
    Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Microsoft Office")

    For i = 0 To 2
     Set objFolderItem = objFolder.ParseName(arrOfficeArray(i))
     Set colVerbs = objFolderItem.Verbs
     For Each objVerb in colVerbs
         If Replace(objVerb.name, "&", "") = "Unpin to Start Menu" Then objVerb.DoIt
     Next
    Next

    For i = 0 To 2
     Set objFolderItem = objFolder.ParseName(arrOfficeArray(i))
     Set colVerbs = objFolderItem.Verbs
     For Each objVerb in colVerbs
         If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt
     Next
    Next


    'Creates logfile in \\server\profiles\%username%\Application Data and AppData\Roaming
    Set logFile = objFSO.CreateTextFile(strAppdata & "\flag.txt", TRUE)
    logFile.WriteLine("Flag.")
    logFile.Close
    End If

     

     



    19 martie 2012 09:21
  • This section:

    For Each objVerb in colVerbs 
         If Replace(objVerb.name, "&", "") = "Unpin to Start Menu" Then objVerb.DoIt 
    Next

    Should be:

    For Each objVerb in colVerbs 
         If Replace(objVerb.name, "&", "") = "Unpin from Start Menu" Then objVerb.DoIt 
    Next

    Because you want to unpin it FROM the Start Menu. Not Unpin To Start Menu

    • Marcat ca răspuns de Millsyboy 18 iulie 2012 09:35
    18 iulie 2012 08:55
  • This section:

    For Each objVerb in colVerbs 
         If Replace(objVerb.name, "&", "") = "Unpin to Start Menu" Then objVerb.DoIt 
    Next

    Should be:

    For Each objVerb in colVerbs 
         If Replace(objVerb.name, "&", "") = "Unpin from Start Menu" Then objVerb.DoIt 
    Next

    Because you want to unpin it FROM the Start Menu. Not Unpin To Start Menu

    The point of teh chosen answer was t addess how to do this without enumerating all of the verbs.  The refrenced artcle has teh correct syntax and speeling for both the pin and unpin actions.  There is no need to enumerate the verbs.  Unstead we can use 'InvokeVerb' directly.

    Follow the link and read the article. It is an excellent explanation on the how and why of verbs.


    ¯\_(ツ)_/¯

    18 iulie 2012 09:17
  • This can be closed.

    Thank you for all your help.

    18 iulie 2012 09:35
  • This mechanism works great, but I actually need to run this script on machines running any number of different languages. The problem there is that the verbs change - they're localized along with the rest of Windows. I've tried the GetLocale() and SetLocale() methods, but, for example, on a machine installed from English media but with the Dutch language pack injected during build, I'm still reporting the locale as 1033 (English) so it doesn't change the localization of the verbs.

    Has anyone done anthing like this? Short of getting the "Pin to taskbar" verb from every localization (will be challenging for double byte languages, I think), I'm not sure how to handle this. The only other thing I'm seeing is a way to do so in Group Policy Preferences, but I don't have control over the GPP in this environment.

    Thanks!

    Andrew


    Andrew Topp

    29 ianuarie 2013 22:27
  • Hi,

    This question has already been marked as answered for a number of months now. If you still need help, please start a new question.

    Bill

    29 ianuarie 2013 22:41
  • OK. Just trying to avoid having this information spread across multiple threads.


    Andrew Topp

    29 ianuarie 2013 22:47