Solved

Using Delphi - how to Pin an Icon to Start Menu (xp style start menu not the classic start menu)

Posted on 2008-10-15
10
1,696 Views
Last Modified: 2013-11-11
Looking for Delphi code on how to add (and remove) a program icon/shortcut to the XP or Vista start menus (xp style start menu not the classic start menu).  I.E. programmatically accomplish the same thing as right clicking on a program icon on the desktop and selecting "Pin to Start Menu".  This option is only available is you are using the xp style start menu not the classic start menu and it is NOT the same thing as creating a shortcut in ...\All Users\Start Menu

Here is a link to page that shows you how to do it via VB script
http://www.microsoft.com/technet/scriptcenter/resources/qanda/nov04/hey1111.mspx

I am using Delphi2007 and I will give extra points for a complete solution.
0
Comment
Question by:undercaffinated
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 14

Accepted Solution

by:
SteveBay earned 350 total points
Comment Utility
Here is the delphi equivalent of that code:

procedure TForm1.Button1Click(Sender: TObject);
var    Shell, OleFolder, OleFolderItem : OleVariant;
begin
   Shell := CreateOleObject('Shell.Application') ;
   OleFolder := Shell.Namespace('C:\Windows\System32');
   OleFolderItem := OleFolder.ParseName('Calc.exe');
   OleFolderItem.InvokeVerb('P&in to Start Menu');
end
0
 

Author Comment

by:undercaffinated
Comment Utility
Thanks for the response.

The result though is not working, at least in Vista.
Even after adding  ComObj  to Uses to make the compiler happy.

No errors, just nothing happens.
Pinning/Unpinning via right click works just fine.  
0
 
LVL 14

Expert Comment

by:SteveBay
Comment Utility
Hmm, Yeah, I can't speak for Vista, it worked fine for me in XP. To be completely honest all I really did was interpret this VB Script: http://www.microsoft.com/technet/scriptcenter/resources/qanda/nov04/hey1111.mspx
0
 

Author Comment

by:undercaffinated
Comment Utility
The following works in XP and Vista:

Uses ComObj,...


procedure TForm1.BtnDoItClick(Sender: TObject);
var
  Shell, OleFolder, OleFolderItem : OleVariant;
  i : integer;
begin

   Shell := CreateOleObject('Shell.Application') ;
   OleFolder := Shell.Namespace('C:\Windows\System32');
   OleFolderItem := OleFolder.ParseName('Calc.exe');
   OleFolderItem.InvokeVerb('P&in to Start Menu');

   for i := 0 to OleFolderItem.Verbs.Count - 1 do
     if OleFolderItem.Verbs.Item(i).Name = 'P&in to Start Menu' then begin
       OleFolderItem.Verbs.Item(i).DoIt;
       break;
     end;

end;
0
 
LVL 14

Expert Comment

by:SteveBay
Comment Utility
Nice work undercaffinated :D

I suspect you could ditch this line as well:
OleFolderItem.InvokeVerb('P&in to Start Menu');
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:undercaffinated
Comment Utility
Thanks SteveBay for your help.

Further testing shows:

Uses ComObj,...


procedure TForm1.Button1Click(Sender: TObject);
var
  Shell, OleFolder, OleFolderItem : OleVariant;
  i : integer;
begin

   Shell := CreateOleObject('Shell.Application') ;
   OleFolder := Shell.Namespace('C:\Windows\System32');
   OleFolderItem := OleFolder.ParseName('Calc.exe');
   OleFolderItem.InvokeVerb('P&in to Start Menu');   //REQUIRED for XP!

   for i := 0 to OleFolderItem.Verbs.Count - 1 do      //REQUIRED for Vista!
     if OleFolderItem.Verbs.Item(i).Name = 'P&in to Start Menu' then begin
       OleFolderItem.Verbs.Item(i).DoIt;
       break;
     end;

end;

//Note that excluding the section(s) not needed for the target OS seems to speed up the execution //significantly  (2-3 seconds on my test pc) so filtering for the OS type could be worth the trouble.
//Have not tested on Windows 2003 or Windows 2008.
0
 

Expert Comment

by:birbilis
Comment Utility
The "P&in to Start Menu" verb most probably won't work at localized versions or systems with another language (than English) MUI (Multi-User Interface) pack activated. Better use "regmon" tool from SysInternals (http://www.sysinternals.com, now Winternals/SysInternals is part of Microsoft) to see what changes to the registry the pin to start menu action does and do the same from your code (Delphi has very good support for writing to the registry using either VCL controls or direct commands and ships with some sample to show how to use them)
0
 

Expert Comment

by:birbilis
Comment Utility
The "P&in to Start Menu" verb most probably won't work at localized versions or systems with another language (than English) MUI (Multi-User Interface) pack activated
0
 
LVL 16

Expert Comment

by:CodedK
Comment Utility
Birbili patrida :)
I 've checked before you posted if there are any changes in the registry using RegShot.
But i couldnt find any !
0
 

Author Comment

by:undercaffinated
Comment Utility
BirBili - thank you for your feedback.

Your comments regarding other languages are probably valid.  If you have access to a system with another language installed or activated maybe you could verify this?

I am very much aware of Delphi's tools for working with the registry.
The first thing I researched/tested when I tried to find a solution was to see if this was something controlled by a Registry setting and I did not find a direct relationship.  If I had found one, I would not have needed to post this question.

The only solutions that I was able to find on this subject were in English and based on VB scripting.  I included a link to the best example I found in the initial post of this thread. If you google this subject you will find that this post is the only one that has a workable (though possibly limited) solution to this question for Delphi.

 I was hoping that someone with expertise in this particular area would be able to come up with a viable solution.


0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now