Solved

Windows startup shortcut

Posted on 2004-08-11
6
226 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 33

Accepted Solution

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to convert wav to mp3 in delphi 9 174
IExtractImage Delphi 14 207
how to draw animated progressbar in Tvirtualstringtree 5 117
How to renew a Delphi rad-studio licence? 5 49
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

895 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

12 Experts available now in Live!

Get 1:1 Help Now