Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6650603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:54:42+00:00 2026-05-26T00:54:42+00:00

function GetDesktopFolder: string; var buf: array[0..MAX_PATH] of Char; pidList: PItemIDList; begin Result := StrNoDesktopFolderFo;

  • 0
function GetDesktopFolder: string;
var
  buf: array[0..MAX_PATH] of Char;
  pidList: PItemIDList;
begin
  Result := StrNoDesktopFolderFo;
  SHGetSpecialFolderLocation(Application.Handle, CSIDL_DESKTOP, pidList);
  if (pidList <> nil) then
    if (SHGetPathFromIDList(pidList, buf)) then
      Result := buf;
end;

procedure p;
var
  i: Integer;
  IObject: IUnknown;
  ISLink: IShellLink;
  IPFile: IPersistFile;
  PIDL: PItemIDList;
  InFolder: array[0..MAX_PATH] of Char;
  TargetName: string;
  LinkName: string;
begin
  TargetName := 'c:\folder\exeFile.exe';//hardcoded example

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

  with ISLink do
  begin
    SetDescription('what ever');
    SetPath(pChar(TargetName)) ;
    SetWorkingDirectory(pChar(ExtractFilePath(TargetName))) ;
  end;

  SHGetSpecialFolderLocation(0, CSIDL_DESKTOPDIRECTORY, PIDL) ;
  SHGetPathFromIDList(PIDL, InFolder) ;

  LinkName := getDesktopFolder+'\';
  i := ;

  LinkName:= linkname+ExtractFileName(TargetName)+'.lnk';

  if LinkName = StrNoDesktopFolderFo then
    Exit;
  if not FileExists(LinkName) then
    IPFile.Save(PWChar(LinkName), False);

  Application.Terminate;
end;

The above code causes a lot of errors in Delphi and cannot run twice…

Any ideas ?

Btw. the source is not originally mine, it was picked up from places on the web.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:54:43+00:00Added an answer on May 26, 2026 at 12:54 am

    I would do it e.g. this way

    uses
      ShlObj, ComObj, ActiveX;
    
    function GetDesktopFolder: string;
    var
      PIDList: PItemIDList;
      Buffer: array [0..MAX_PATH-1] of Char;
    begin
      Result := '';
      SHGetSpecialFolderLocation(Application.Handle, CSIDL_DESKTOP, PIDList);
      if Assigned(PIDList) then
        if SHGetPathFromIDList(PIDList, Buffer) then
          Result := Buffer;
    end;
    
    function CreateDesktopShellLink(const TargetName: string): Boolean;
    var
      IObject: IUnknown;
      ISLink: IShellLink;
      IPFile: IPersistFile;
      PIDL: PItemIDList;
      LinkName: string;
      InFolder: array [0..MAX_PATH-1] of Char;
    begin
      Result := False;
    
      IObject := CreateComObject(CLSID_ShellLink);
      ISLink := IObject as IShellLink;
      IPFile := IObject as IPersistFile;
    
      with ISLink do
      begin
        SetDescription('Description ...');
        SetPath(PChar(TargetName));
        SetWorkingDirectory(PChar(ExtractFilePath(TargetName)));
      end;
    
      SHGetSpecialFolderLocation(0, CSIDL_DESKTOPDIRECTORY, PIDL);
      SHGetPathFromIDList(PIDL, InFolder) ;
    
      LinkName := IncludeTrailingBackslash(GetDesktopFolder);
      LinkName := LinkName + ExtractFileName(TargetName) + '.lnk';
    
      if not FileExists(LinkName) then
        if IPFile.Save(PWideChar(LinkName), False) = S_OK then
          Result := True;
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      if CreateDesktopShellLink('C:\Folder\ExeFile.exe') then
        ShowMessage('Link has been created ...');
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

function returnsAnArray () { return array ('test'); } echo returnsAnArray ()[0]; generates a syntax
function register_contact ($person = array()) { $nogood = false; foreach ($person as $val) {
function get_total_adults() { $sql = SELECT SUM(number_adults_attending) as number_of_adults FROM is_nfo_rsvp; $result = mysql_query($sql)
function DeleteData(ID) { var ctrlId=ID.id; var divcontents=document.getElementById(ctrlId).innerHTML; var tabid=ctrlId.replace(/div/,'tab'); var tabcontents=document.getElementById(tabid).innerHTML; alert(document.getElementById(tabid).innerHTML); document.getElementById(tabid).innerHTML=<TBody><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr></TBody>; document.getElementById(ctrlId).innerHTML='';
function runProcess(){ var todo = items.concat(); setTimeout(function(){ process(todo.shift()); if(todo.length > 0){ setTimeout(arguments.callee, 25); }
function simple_form($form_state) { $form['item'] = array('#type' => 'hidden', '#value' => 'some_value'); $form['#action'] = 'http://external-website.com/';
function manageVoting() { $(div.votemaincontainer).each(function () { // variable Declaration and intialization. var myRating =
function openFile(file, object) { var extension = file.substr( (file.lastIndexOf('.') +1) ); var fileName =
function dlLink(title, currentArray, currentIndex, currentOpts) { var img = new Image(); img.src = 'Gallery/Wallpapers/'
function manageVoting() { $('div.votemaincontainer').each(function() { // variable declaration and intialization var parameter = $(this).find('#[id$=

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.