Pin programs via script or un pin

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Krump
Posts: 45
Joined: 02 Dec 2014 14:53

Pin programs via script or un pin

#1 Post by Krump » 05 Feb 2015 05:01

Hi,
I need batch script or another solution to pin icons to taskbar. I was looking for in google, and people write about scripts in .vbs. I check it. It doesn't work in my computers:
https://gist.github.com/sirlancelot/368910
http://blogs.technet.com/b/deploymentgu ... cript.aspx
msfn.org/board/topic/134662-pin-items-to-taskbar-andor-start-menu-during-deploy/


I will describe my problem:
I must set 3 icons on taskbar, but I have 5 icons (this 3 icons what I must set are there) after installing system. So I clean all task bar in my script:

Code: Select all

REG DELETE HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband /F
taskkill /f /im explorer.exe
start explorer.exe

And in next step I want pin 3 icons, but I need script for it.

Second option is: unpin 2 out of 5, but I need script for it.
Third option is: Set everything in one computer and export reg settings and import it on other computers, but is it work?
Maybe is another option?

rojo
Posts: 26
Joined: 14 Jan 2015 13:51

Re: Pin programs via script or un pin

#2 Post by rojo » 05 Feb 2015 14:53

Programmatically pin to taskbar seems relevant. You can use the Pin to Taskbar or Unpin from Taskbar verb through Shell.Application using VBScript or JScript. I'd probably do it as a JScript hybrid.

Krump
Posts: 45
Joined: 02 Dec 2014 14:53

Re: Pin programs via script or un pin

#3 Post by Krump » 06 Feb 2015 09:04

I saw this article, but i don't know where this program have source to information about unpined aplication

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: Pin programs via script or un pin

#4 Post by Dos_Probie » 07 Feb 2015 19:51

Here is a batch and vbs that I have been using successfully to do the pinning or unpinning that may work for you.
Note the 1 to pin or 0 to Unpin, revise as needed.
~DP

Batch Script

Code: Select all

@echo off
%~d0
cd %~d0%~p0
:: PIN SHORTCUTS TO TASKBAR..
WScript.exe "%~dp0Pin.vbs" "%programfiles%\CCleaner\CCleaner.exe" 1
WScript.exe "%~dp0Pin.vbs" "%programfiles%\CDBurnerXP\cdbxpp.exe" 1
WScript.exe "%~dp0Pin.vbs" "%programfiles%\RadioSure\RadioSure.exe" 1
WScript.exe "%~dp0Pin.vbs" "%programfiles%\Games Explorer\Games.lnk" 1
WScript.exe "%~dp0Pin.vbs" "%programfiles%\Windows Defender\MSASCui.exe" 1
WScript.exe "%~dp0Pin.vbs" "%programfiles%\Adobe\Reader 11.0\Reader\AcroRd32.exe" 1

Vbs Script

Code: Select all

'************************************************
' Pin and unpin shortcuts to Windows 7/8 Taskbar
' ~DosProbie - 07.15.13
' Pin.vbs
'************************************************
' ### NOTES
' *** Usage - Pin.vbs
' *** WScript.exe "%~dp0\%~dp0\Pin.vbs" [drive:][path]filename [Argument]
' *** [Arguments] = 0 1 2
' *** 0 = Unpin from Taskbar
' *** 1 = Pin to Taskbar
' *** 2 = Install

 Set objShell = CreateObject("Shell.Application")
 Set filesystem = CreateObject("scripting.Filesystemobject")
 If filesystem.FileExists(Wscript.Arguments(0)) Then
  Set objFolder = objShell.Namespace(filesystem.GetParentFolderName(Wscript.Arguments(0)))
  Set objFolderItem = objFolder.ParseName(filesystem.GetFileName(WScript.Arguments(0)))
  Set colVerbs = objFolderItem.Verbs
 
  Select case WScript.Arguments(1)
   case 0
    For Each objVerb in colVerbs
     If Replace(objVerb.name, "&", "") = "Unpin from Taskbar" Then objVerb.DoIt
    Next
   case 1
    For Each objVerb in colVerbs
     If Replace(objVerb.name, "&", "") = "Pin to Taskbar" Then objVerb.DoIt
    Next
   case 2
    For Each objVerb in colVerbs
     If Replace(objVerb.name, "&", "") = "Install" Then objVerb.DoIt
    Next
  End Select
 End If



Krump
Posts: 45
Joined: 02 Dec 2014 14:53

Re: Pin programs via script or un pin

#5 Post by Krump » 09 Feb 2015 07:33

Sorry but your script isn't work. I change in bat only directory and aplication name.

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: Pin programs via script or un pin

#6 Post by Dos_Probie » 09 Feb 2015 08:07

Krump wrote:Sorry but your script isn't work. I change in bat only directory and aplication name.


You did not specify what OS Version, but has always worked for me on Windows 7 and 8.1.' Why don't you POST your bat file with directory path and app so we can look at it..
~DP

Krump
Posts: 45
Joined: 02 Dec 2014 14:53

Re: Pin programs via script or un pin

#7 Post by Krump » 10 Feb 2015 02:11

Ok, sorry my bad.
Two systems: Win 7 SP1 Enterprise and Win 8.1 Enterprise

Bat Script

Code: Select all

@echo off
%~d0
cd %~d0%~p0
:: PIN SHORTCUTS TO TASKBAR..
WScript.exe "%~dp0Pin.vbs" "%userprofile%\Desktop\Builder CPP.exe" 1


VBS Script unchanged

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: Pin programs via script or un pin

#8 Post by Dos_Probie » 10 Feb 2015 04:51

Make sure that the batch and vbs are together and run from the same directory.
I just made shortcut off desktop with W7 and W8.1 as admin and no issues.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Pin programs via script or un pin

#9 Post by penpen » 10 Feb 2015 05:31

If that is not the reason, maybe localization causes this issue, i've changed the vbs to list all verb names (untested, may contain flaws):

Code: Select all

 '************************************************
' Pin and unpin shortcuts to Windows 7/8 Taskbar
' ~DosProbie - 07.15.13
' Pin.vbs
'************************************************
' ### NOTES
' *** Usage - Pin.vbs
' *** WScript.exe "%~dp0\%~dp0\Pin.vbs" [drive:][path]filename [Argument]
' *** [Arguments] = 0 1 2
' *** 0 = Unpin from Taskbar
' *** 1 = Pin to Taskbar
' *** 2 = Install
' *** <no> = List all Verbs

 Set objShell = CreateObject("Shell.Application")
 Set filesystem = CreateObject("scripting.Filesystemobject")
 If filesystem.FileExists(Wscript.Arguments(0)) Then
  Set objFolder = objShell.Namespace(filesystem.GetParentFolderName(Wscript.Arguments(0)))
  Set objFolderItem = objFolder.ParseName(filesystem.GetFileName(WScript.Arguments(0)))
  Set colVerbs = objFolderItem.Verbs
 
  If WScript.Arguments.Length = 1 Then
   For Each objVerb in colVerbs
    WScript.Echo Replace(objVerb.name, "&", "")
   Next
  ElseIf WScript.Arguments.Length > 1 Then
   Select case WScript.Arguments(1)
    case 0
     For Each objVerb in colVerbs
      If Replace(objVerb.name, "&", "") = "Unpin from Taskbar" Then objVerb.DoIt
     Next
    case 1
     For Each objVerb in colVerbs
      If Replace(objVerb.name, "&", "") = "Pin to Taskbar" Then objVerb.DoIt
     Next
    case 2
     For Each objVerb in colVerbs
      If Replace(objVerb.name, "&", "") = "Install" Then objVerb.DoIt
     Next
   End Select
  End If
 End If

Just call it using cscript within a batch:

Code: Select all

@echo off
%~d0
cd %~d0%~p0
:: List all Verbs available for your file
CScript.exe "%~dp0Pin.vbs" "%userprofile%\Desktop\Builder CPP.exe"
In that case you may replace the 3 Strings "Unpin from Taskbar", "Pin to Taskbar", and "Install" with the localized version.

penpen

Krump
Posts: 45
Joined: 02 Dec 2014 14:53

Re: Pin programs via script or un pin

#10 Post by Krump » 11 Feb 2015 01:45

.bat and .vbs are in the same directory (User Desktop)

continue during isn't work.

With 1
example:

Code: Select all

CScript.exe "%~dp0Pin.vbs" "%userprofile%\Desktop\Builder CPP.exe" 1

When I run as admin in console I don't have any flags.
When run as user I have:
Redirecting output to win32trace remot collector


Without1 1:
example:

Code: Select all

CScript.exe "%~dp0Pin.vbs" "%userprofile%\Desktop\Builder CPP.exe"

When I run as admin in console I don't have any flags.
When run as user I have:
Redirecting output to win32trace remot collector
Run as admin
solve the compatibility issue

Edit with Notepad++
Scan using the program System Center Endpoint Protection...

Pin to taskbar
Pin to Start menu
Restore previous versions

Cut
Copy
Create shortcut
Delete
Change Name
Properties

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Pin programs via script or un pin

#11 Post by penpen » 11 Feb 2015 07:40

I did not expected to see "Pin to taskbar" with a small case letter 't'. If that is no typo (i'm unsure because of "remot" without an 'e'), but some kind of localization, you should replace "Pin to Taskbar" in the vbs with "Pin to taskbar" and (hopefully) that works.

In that case you should also test the other two strings ("Unpin from Taskbar", and "Install").
If you want to run the script on multiple PCs with different letter case versions, you may do a comparison that ignores the letter case ("test.vbs"):

Code: Select all

If 0 = StrComp (Replace ("&Pin to taskbar", "&", ""), "Pin to Taskbar", 1) Then
   WScript.Echo Replace ("&Pin to taskbar", "&", ""), " == ", "Pin to Taskbar"
Else
   WScript.Echo Replace ("&Pin to taskbar", "&", ""), " != ", "Pin to Taskbar"
End If

penpen

Krump
Posts: 45
Joined: 02 Dec 2014 14:53

Re: Pin programs via script or un pin

#12 Post by Krump » 11 Feb 2015 07:55

Huh, from what I understand it's fork only if write corect sentense?

Because i translate u everything from my language (Polish)... you dont tell it's important what called string.

So where is "Pin to Taskbar" I must write it in my language (what I have the right-click)?

Pin to Taskbar -> Przypnij do paska zadań
Install -> Instaluj

etc.

I wrong?

Krump
Posts: 45
Joined: 02 Dec 2014 14:53

Re: Pin programs via script or un pin

#13 Post by Krump » 11 Feb 2015 08:02

Yep it's that problem.

I change in your first version Pin to Taskbar to Przypnij do paska zadań and it's work.

It's a huge progres!

Thanks Guys!

But it's not everything. Please tell mi, how use this script to unpin Windows Store in win 8.1 (what directory)?
Pining outlook, lync, word, excel works, but i don't know how unpin store, because is a shell aplication

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Pin programs via script or un pin

#14 Post by penpen » 11 Feb 2015 09:13

I have no Windows 8 so i can't test it, our admin has removed the Windows store from taskbar by using this (batch) script ("delWindowsStore.bat"):

Code: Select all

for %%a in ("C:\ProgramData\Microsoft\Windows\Start Menu\Programs\windows store.lnk") do (
   attrib -R -S "%%~a"
   del "%%~a"
)
Notes:
She says the drawback is, that this solution is not user specific.
The directory may differ.
If you may need it in future it may be better to move this link to another location (instead of deleting it).

penpen

Krump
Posts: 45
Joined: 02 Dec 2014 14:53

Re: Pin programs via script or un pin

#15 Post by Krump » 12 Feb 2015 06:56

Unfortunately it isn't work. Any sugestions?

ouh! I try using your vbs script with directory:

Code: Select all

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Sklep.lnk
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Store.lnk
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\winstore.lnk
%windir%\WinStore\Winstore.htm

But nothing works.


I invented any way. I can clean all taskband:

Code: Select all

REG DELETE HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Taskband /F
taskkill /f /im explorer.exe
start explorer.exe

and pin icons. With Internet explorer, outlook and lync isn't problem. But how Pin windows explorer?

Post Reply