How do I Create a Folder and Short cuts in start menu

eNarc used Ask the Experts™
Hi how do I create Folders and Shortcuts in the Start Menu?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
The simplest way, is to use the regular file system location such as:

C:\Documents and Settings\<user>\Start Menu

Now, I would also pull the following environment variables to help you determine the location regardless of operating system and user:

HOMEDRIVE, which for me is "C:"
HOMEPATH, which for me is "\Documents and Settings\Tom"
USERPROFILE, which for me is "C:\Documents and Settings\Tom"

So, you could either concatenate HOMEDRIVE+HOMEPATH+"\Start Menu", or USERPROFILE+"\Start Menu"
try this:

first of all add to USES the following

ShlObj, ActiveX, ComObj

Open in new window

for creating a link in Start Menu copy and paste the following snippet

procedure TForm1.Button1Click(Sender: TObject);
    IObject : IUnknown;
    ISLink : IShellLink;
    IPFile : IPersistFile;
    PIDL : PItemIDList;
    InFolder : array[0..MAX_PATH] of Char;
    TargetName : String;
    LinkName : WideString;

    IObject := CreateComObject(CLSID_ShellLink) ;
    ISLink := IObject as IShellLink;
    IPFile := IObject as IPersistFile;

    with ISLink do
      SetPath(pChar(TargetName)) ;
      SetWorkingDirectory(pChar(ExtractFilePath(TargetName))) ;

    InFolder := 'C:\Users\Barlet\AppData\Roaming\Microsoft\Windows\Start Menu\Programs';
    LinkName := InFolder + '\Delphi Created Link.lnk';
    IPFile.Save(PWChar(LinkName), false) ;

Open in new window

to create a Directory copy and paste the following snippet

procedure TForm1.Button2Click(Sender: TObject);
ForceDirectories('C:\Users\Barlet\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Delphi');

Open in new window

remember to change the path's... btw change only where is [Barlet] and put your Windows username

the example code is taken from:
to create a Directory
uses ..., SysUtils, ShlObj;

function TmainF.GetAutorunFolder(val: Cardinal): String;
  Folder: array[0..255] of Char; //path to StartUp
  List: PitemidList; //list of "special" folders
  SHGetSpecialFolderLocation(0, val, List);
  FillChar(Folder, SizeOf(Folder), 0);
  SHGetPathFromIDList(List, @Folder);
  Result := IncludeTrailingPathDelimiter(folder);

ForceDirectories(GetAutorunFolder(CSIDL_COMMON_STARTUP) + 'Your Folder'); //Create folder at Start Menu for all users 

ForceDirectories(GetAutorunFolder(CSIDL_STARTUP) + 'Your Folder'); //Create folder at Start Menu for current user 

Open in new window

barlet code show how to create shortcut and my code show how to create folder
Mike McCrackenSenior Consultant
Most Valuable Expert 2011
Top Expert 2013

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial