Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

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,922 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

705 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