• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1630
  • Last Modified:

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
0
BLACK THANOS
Asked:
BLACK THANOS
  • 11
  • 9
  • 8
3 Solutions
 
Run5kCommented:
Regis, it's nice to see you again.

I am not a VBScript guru myself, but coincidentally enough one of the EE community members who is contributed to a very similar question that I have been monitoring recently...

http://www.experts-exchange.com/Q_27322267.html
0
 
RobSampsonCommented:
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.
0
 
Run5kCommented:
@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!
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
BLACK THANOSAuthor Commented:
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
0
 
Run5kCommented:
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?
0
 
BLACK THANOSAuthor Commented:
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

0
 
Run5kCommented:
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.
0
 
RobSampsonCommented:
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

0
 
BLACK THANOSAuthor Commented:
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)
0
 
RobSampsonCommented:
OK, try this.  I should have used objFile.ParentFolder.

Rob.
arrFileNames = Array( _
	"C:\Program Files\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.ParentFolder & "\")
		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

0
 
Run5kCommented:
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?
0
 
RobSampsonCommented:
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.
0
 
BLACK THANOSAuthor Commented:
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.
0
 
RobSampsonCommented:
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.
0
 
BLACK THANOSAuthor Commented:
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"

0
 
BLACK THANOSAuthor Commented:
It still didnt pin the item. You may have noticed I tried something as simple as Notepad.exe
0
 
BLACK THANOSAuthor Commented:
Stop the presses. I know what the problem is........!!!!!!!!!!!!!!!!!!!
0
 
RobSampsonCommented:
LOL!  Do tell.....
0
 
BLACK THANOSAuthor Commented:
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?
0
 
RobSampsonCommented:
Oh!! LOL!  Whoops!  Missed that!!!

Sorry for all the run around....that should be as simple as changing this:
                  If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then objVerb.DoIt

to this:
                  If Replace(objVerb.name, "&", "") = "Pin to Taskbar" Then objVerb.DoIt

Rob.
0
 
Run5kCommented:
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?
0
 
RobSampsonCommented:
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.
0
 
BLACK THANOSAuthor Commented:
RobSampson, you and Run5k are premo mucho smarto. It works like a charm. Guys, how should I split the points.

0
 
Run5kCommented:
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!
0
 
RobSampsonCommented:
I'm fine with whatever you feel is appropriate.  Thanks Run5k for your input.

Rob.
0
 
BLACK THANOSAuthor Commented:
RobSampson and Run5k exemplfy excellence for the Experts Exchange Community.

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

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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 11
  • 9
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now