Solved

Windows startup shortcut

Posted on 2004-08-11
6
224 Views
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!
0
Comment
Question by:skynergy
  • 3
  • 2
6 Comments
 
LVL 4

Expert Comment

by:alikoank
Comment Utility
for creating shortcuts take a look at:

http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20406985.html?query=delphi+create+shortcut&clearTAFilter=true

removing a shortcut is  a simple file delete operation.
0
 
LVL 4

Expert Comment

by:alikoank
Comment Utility
You can get the location of Startup folder from registry:

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

Author Comment

by:skynergy
Comment Utility
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!
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 4

Expert Comment

by:alikoank
Comment Utility
Well, doing your work is not the same as helping.

I suggest you take a look at http://www.rentacoder.com
0
 

Author Comment

by:skynergy
Comment Utility
I have the following code in one of my units that I was using:
procedure CreateShortcut(FileName,Args: string;uninstall : boolean);
var
LPUnknown : IUnknown;
pShlLnk : IShellLink;
pszFileName : IPersistFile;
Dir,LinkName : string;
FullPath : WideString;
begin
  LPUnknown := CreateComObject(CLSID_ShellLink);
  pShlLnk := LPUnknown as IShellLink;
  pszFileName := LPUnknown as IPersistFile;
  pShlLnk.SetPath(PChar(FileName));
  pShlLnk.SetArguments(PChar(Args));
  with TRegIniFile.Create('Software\MicroSoft\Windows\CurrentVersion\Explorer') do
       try
         LinkName := ChangeFileExt(FileName, '.lnk');
         LinkName := ExtractFileName(LinkName);
         Dir := ReadString('Shell Folders', 'Startup', '');
         if Dir <> '' then
            begin
              FullPath := Dir + '\' + LinkName;
            if uninstall then
               DeleteFile(FullPath)
            else
               pszFileName.Save(PWChar(FullPath), False);
         end;
       finally
         Free;
       end;
end;

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.
0
 
LVL 33

Accepted Solution

by:
Slick812 earned 125 total points
Comment Utility
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;
const
IID_IPersistFile: TGUID = (D1:$0000010B;D2:$0000;D3:$0000;D4:($C0,$00,$00,$00,$00,$00,$00,$46));

var
sLink: IShellLink;
PersFile: IPersistFile;
begin
  Result := false;
  CoInitialize(nil);
  if SUCCEEDED(CoCreateInstance(CLSID_ShellLink, nil,
               CLSCTX_INPROC_SERVER, IID_IShellLinkA, sLink)) then
  begin
    sLink.SetPath(PChar(Path2Obj)); // I think you can add a startup parameter to the string for an executable
    {sLink.SetDescription(PChar(Desc));}
    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
    begin
      PersFile.Save(StringToOLEStr(Path2Link),TRUE);
      Result := true;
    end;
  end;
  CoUninitialize();
end;

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now