Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Windows startup shortcut

Posted on 2004-08-11
6
Medium Priority
?
253 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

670 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