Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Windows startup shortcut

Posted on 2004-08-11
6
Medium Priority
?
255 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
ID: 11770343
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
ID: 11770375
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
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!
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:alikoank
ID: 11771363
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
ID: 11771501
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 34

Accepted Solution

by:
Slick812 earned 500 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;
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Screencast - Getting to Know the Pipeline

783 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