Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1970
  • Last Modified:

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

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
undercaffinated
Asked:
undercaffinated
  • 4
  • 3
  • 2
  • +1
1 Solution
 
SteveBayCommented:
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
 
undercaffinatedAuthor Commented:
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
 
SteveBayCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
undercaffinatedAuthor Commented:
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
 
SteveBayCommented:
Nice work undercaffinated :D

I suspect you could ditch this line as well:
OleFolderItem.InvokeVerb('P&in to Start Menu');
0
 
undercaffinatedAuthor Commented:
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
 
birbilisCommented:
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
 
birbilisCommented:
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
 
CodedKCommented:
Birbili patrida :)
I 've checked before you posted if there are any changes in the registry using RegShot.
But i couldnt find any !
0
 
undercaffinatedAuthor Commented:
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

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now