Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
1,953 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 1400 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
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!

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

971 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