Link to home
Start Free TrialLog in
Avatar of BLACK THANOS
BLACK THANOSFlag for United States of America

asked on

How do I pin an application to the taskbar in windows 7 programatically.

Good evening Experts,

Is there a quick and dirty way to pin and un-pin applications to the taskbar either via command line or vbscript. I dont want some overly complicated VBA, C++, C#, or Java based solution that I have to study for hours and hours to understand. Just something simple that will allow me to pin or un-pin applications to the taskbar.

Regards,
Regis
SOLUTION
Avatar of Run5k
Run5k
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi, thanks for linking to a solution I have offered ;-)

The code there will pin items.  I haven't yet tested a scenario to unpin items, but I can try to assist with that if required.  I won't be able to do any testing until early next week though.

Regards,

Rob.
@Rob, thanks for chiming in!

@Regis, if Rob's linked solution suits your needs please ensure that you at least split the credit between our comments so that he actually receives the proper credit for his great work.  Thanks!
Avatar of BLACK THANOS

ASKER

I like the way you guys collaborate. I will look at the solution and get back to you asap.

Good to hear from you too Run5k
Rob, I started monitoring the other question to learn a few tips.  As I said, I am definitely not a VBScript guru so I certainly appreciate your advice!  In your opinion, what would be the easiest was to actually implement something like this on an end-user's machine?  Perhaps utilizing a RunOnce registry key?
Run5k, I ran the code snippet that you referrred to:

,but I get the following error:
Microsoft VBScript runtime error: Object doesn't support this property or method: 'objFile.Parent'
Can you or RobSamson shed some light on this??
arrFileNames = Array( _
	"C:\Program Files (x86)\Microsoft Office\Office14\winword.exe", _
	"C:\Program Files (x86)\Microsoft Office\Office14\winword.exe", _	
	"C:\Program Files (x86)\Microsoft Office\Office14\winword.exe", _
	"C:\Program Files (x86)\Microsoft Office\Office14\winword.exe")
	
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShellApp = CreateObject("Shell.Application")
Set objShell = CreateObject("WScript.Shell")
For Each strFilePath In arrFileNames
	Set objFile = objFSO.GetFile(strFilePath)
	Set objFolder = objShellApp.Namespace(objFile.Parent)
	Set objFolderItem = objFolder.ParseName(objFile.Name)
	Set colVerbs = objFolderItem.Verbs
	For Each objVerb In colVerbs
		If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt
	Next
Next

Open in new window

Regis,

I will defer to Rob's expertise in the VBScript department.  He is easily the EE community's foremost expert within that topic area, and is typically very active on the boards.  I'm sure he will reply back to you rather soon.
Hi guys, sorry, I was away for the weekend.

Regis, please try this, in which I have just added a check for the file before attempting to bind to it.

Also, if you only need to pin one item, you only need one element in the array.

I have added two WScript.Echo statements which you are welcome to comment out or delete when you have finished testing.

Regards,

Rob.
arrFileNames = Array( _
	"C:\Program Files (x86)\Microsoft Office\Office14\winword.exe" _
	)
	
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShellApp = CreateObject("Shell.Application")
Set objShell = CreateObject("WScript.Shell")
For Each strFilePath In arrFileNames
	If objFSO.FileExists(strFilePath) = True Then
		Set objFile = objFSO.GetFile(strFilePath)
		Set objFolder = objShellApp.Namespace(objFile.Parent)
		Set objFolderItem = objFolder.ParseName(objFile.Name)
		Set colVerbs = objFolderItem.Verbs
		For Each objVerb In colVerbs
			If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt
		Next
		WScript.Echo strFilePath & " has been pinned."
	Else
		WScript.Echo "Could not find " & strFilePath
	End If
Next

Open in new window

I still get this error:
C:\INSTALL\Untitled6.vbs(24, 3) Microsoft VBScript runtime error: Object doesn't support this property or method: 'objFile.Parent'

at:
            Set objFolder = objShellApp.Namespace(objFile.Parent)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Rob, we definitely appreciate the input!  As I said earlier, in your opinion what would be the best way to actually implement something like this on an end-user's machine?  Perhaps utilizing a RunOnce registry key in some format?
RunOnce would run before the user interface loaded, so I'm not sure that would be able to pin items.

I would probably just use the script at Logon, but also write a flag somewhere that would tell the script whether the items had already been pinned, to avoid pinning it everytime....although I don't think that would be a problem anyway.

Rob.
I ran the updated script and it came back with no errors, but I didnt actually see the pinned item on the taskbar.

Also,

I changed C:\Program Files\Microsoft Office\Office14\winword.exe

To

C:\Program Files (x86)\Microsoft Office\Office14\winword.exe , because my version of office is the 32bit versions on my Windows 7 64 bit operating systems.
It did work for me....does it make any difference if you run cmd.exe by right-clicking, then select "Run As Administrator", then type the following:
c:\windows\syswow64\cscript.exe c:\scripts\PinItem.vbs

Rob.
I tried this :

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Windows\system32>CD ..

C:\Windows>CD SYSWOW64

C:\Windows\SysWOW64>cscript.exe "N:\INSTALL HOME\scratch.vbs"
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Windows\System32\notepad.exe has been pinned.

C:\Windows\SysWOW64>

I did it as "RUN AS ADMINISTRATOR"

It still didnt pin the item. You may have noticed I tried something as simple as Notepad.exe
Stop the presses. I know what the problem is........!!!!!!!!!!!!!!!!!!!
LOL!  Do tell.....
RobSamson,
Your script is working at advertised.
It actually pinned word and notepad to the start menu.

However, this is not the solution I asked for. If you will refer to the original post, it requires a solution to pin to the taskbar , not the startmenu. Is this a simple change?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Rob, this needs to run with full admin privileges?  In other words, could it be placed within the C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup folder and still run effectively?
No, it won't need to run with admin rights.....that was just a test....the problem was that we were pinning items to the wrong place, so we thought it didn't work.

It should therefore still work fine if it is placed in that location.

Rob.
RobSampson, you and Run5k are premo mucho smarto. It works like a charm. Guys, how should I split the points.

Honestly, please give Rob all of the credit.  I'm always glad to help, but in this instance I simply pointed the VBScript guru in your direction!
I'm fine with whatever you feel is appropriate.  Thanks Run5k for your input.

Rob.
RobSampson and Run5k exemplfy excellence for the Experts Exchange Community.

Regis T. Hyde
Doctoral Learner
BSB/IS, MIS
I wouldnt have gotten to RobSamspon if not for you Run5k, so I allocated the points I thought appropriate.

Regards,
Regis
Thank you for the kind words... always glad to help!