Windows startup shortcut

Posted on 2004-08-11
Last Modified: 2010-04-05
I am looking for a free component or code to 1. add a shortcut to / 2. delete the same shortcut from the windows startup folder for 9x, NT, 2000 & XP for the current user. The shortcut must start in a specified working directory and must be able to start with a startup parameter to it. Thanx in advance!
Question by:skynergy
  • 3
  • 2

Expert Comment

ID: 11770343
for creating shortcuts take a look at:

removing a shortcut is  a simple file delete operation.

Expert Comment

ID: 11770375
You can get the location of Startup folder from registry:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders

Author Comment

ID: 11771201
Thanx for your reply but can you please provide all the code in this section (my question area). I would really appreciate that. I need the complete code because unluckily I do not have the time to figure out bits of code from various places. I need one complete procedure or a component that will do what I asked in my question. Thanx in advance!
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.


Expert Comment

ID: 11771363
Well, doing your work is not the same as helping.

I suggest you take a look at

Author Comment

ID: 11771501
I have the following code in one of my units that I was using:
procedure CreateShortcut(FileName,Args: string;uninstall : boolean);
LPUnknown : IUnknown;
pShlLnk : IShellLink;
pszFileName : IPersistFile;
Dir,LinkName : string;
FullPath : WideString;
  LPUnknown := CreateComObject(CLSID_ShellLink);
  pShlLnk := LPUnknown as IShellLink;
  pszFileName := LPUnknown as IPersistFile;
  with TRegIniFile.Create('Software\MicroSoft\Windows\CurrentVersion\Explorer') do
         LinkName := ChangeFileExt(FileName, '.lnk');
         LinkName := ExtractFileName(LinkName);
         Dir := ReadString('Shell Folders', 'Startup', '');
         if Dir <> '' then
              FullPath := Dir + '\' + LinkName;
            if uninstall then
               pszFileName.Save(PWChar(FullPath), False);

It works but it doesn't create a shortcut and set the Start In property. That's why I asked in my question about the working directory for the Startup folder. I wasn't really asking you to do my work but merely to provide me with more complete code. I will have a look at the link that you provided. Thank you. I do however appreciate your help so far.
LVL 33

Accepted Solution

Slick812 earned 125 total points
ID: 11804580
hello  skynergy , , I have read over your question and your comments, you seem to want to create a short-cut in the current user's Start-Up folder? and then you posted code to create a shortcut in the startup folder, and you say that this code works - - - - OK that much I understand, , but then you say

"but it doesn't create a shortcut and set the Start In property"

which I do not really understand, about the "Start In property" and you say something about the  "Working directory", maybe these are the same thing? ?

anyway, you might could say more about what the shortcut that you create with that code, does not work or does not do, or the problem you have with it, is it just the working directory that you need in there? ?

Here is some code that is a function to create a shortcut -

function CreateLink(Path2Obj,Path2Link,WorkingDir,Path2Icon: string; IconNumber: Integer): Boolean;
IID_IPersistFile: TGUID = (D1:$0000010B;D2:$0000;D3:$0000;D4:($C0,$00,$00,$00,$00,$00,$00,$46));

sLink: IShellLink;
PersFile: IPersistFile;
  Result := false;
  if SUCCEEDED(CoCreateInstance(CLSID_ShellLink, nil,
               CLSCTX_INPROC_SERVER, IID_IShellLinkA, sLink)) then
    sLink.SetPath(PChar(Path2Obj)); // I think you can add a startup parameter to the string for an executable
    if Length(WorkingDir) > 2 then
    if DirectoryExists(WorkingDir) then
    sLink.SetWorkingDirectory(PChar(WorkingDir)); // sets the working diecrory
    if Length(Path2Icon) > 2 then
    if FileExists(Path2Icon) then
    sLink.SetIconLocation(PChar(Path2Icon),IconNumber); // not really needed most of the time
    if SUCCEEDED(sLink.QueryInterface(IID_IPersistFile,PersFile)) then
      Result := true;

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
maybe something in this will help you?

I use an alternative to the usuall way in Delphi to do this with the

ShellObject := CreateComObject(CLSID_ShellLink);
  LinkFile    := ShellObject as IPersistFile;
  ShellLink   := ShellObject as IShellLink;

but that works also

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

777 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