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

eNarc
eNarc used Ask the Experts™
on
Hi how do I create Folders and Shortcuts in the Start Menu?
Comment
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"
Commented:
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);
var
    IObject : IUnknown;
    ISLink : IShellLink;
    IPFile : IPersistFile;
    PIDL : PItemIDList;
    InFolder : array[0..MAX_PATH] of Char;
    TargetName : String;
    LinkName : WideString;
 begin

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

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

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

Open in new window



to create a Directory copy and paste the following snippet

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

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:

http://delphi.about.com/od/windowsshellapi/a/create_lnk.htm
http://www.delphibasics.co.uk/RTL.asp?Name=ForceDirectories
Commented:
to create a Directory
uses ..., SysUtils, ShlObj;

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

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

Commented:
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

Commented:
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