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,757 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
ID: 22727899
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
ID: 22732685
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
ID: 22732772
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:undercaffinated
ID: 22733265
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
ID: 22733335
Nice work undercaffinated :D

I suspect you could ditch this line as well:
OleFolderItem.InvokeVerb('P&in to Start Menu');
0
 

Author Comment

by:undercaffinated
ID: 22733648
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
ID: 22738883
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
ID: 22738888
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
ID: 22739151
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
ID: 22742238
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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

803 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