type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
ShellObject: IUnknown;
ShellLink: IShellLink; //ComObj unit
PersistFile: IPersistFile; //ActiveX unit
LinkFileName: WideString;
Reg: TRegistry;
RegStr, Subfolder, ParamString, FLinkName, FileName, WorkingDirectory : String;
i, RunAs : Integer;
begin
Reg := TRegistry.Create; //Registry unit
with Reg do
try
RootKey := HKEY_CURRENT_USER;
OpenKey('\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders', True);
RegStr := 'Desktop'; //'Start Menu','Programs','Startup';'Personal'
Subfolder := ''; //'\MyProgram' ---Start Menu
RegStr := ReadString(RegStr) + Subfolder;
except
end;
Reg.Free;
//CreatePath
for i := 1 to Length(RegStr) do
if RegStr[i] = '\' then
CreateDir(Copy(RegStr, 1, i));
ShellObject := CreateComObject(CLSID_ShellLink); //ComObj unit, ShlObj unit
ShellLink := ShellObject as IShellLink;
PersistFile := ShellObject as IPersistFile; //ActiveX
<!--CodeS-->
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Registry, ComObj, ShlObj, ActiveX;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
ShellObject: IUnknown;
ShellLink: IShellLink; //ComObj unit
PersistFile: IPersistFile; //ActiveX unit
LinkFileName: WideString;
Reg: TRegistry;
RegStr, Subfolder, ParamString, FLinkName, FileName, WorkingDirectory : String;
i, RunAs : Integer;
begin
Reg := TRegistry.Create; //Registry unit
with Reg do
try
RootKey := HKEY_CURRENT_USER;
OpenKey('\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders', True);
RegStr := 'Desktop'; //'Start Menu','Programs','Startup';'Personal'
Subfolder := ''; //'\MyProgram' ---Start Menu
RegStr := ReadString(RegStr) + Subfolder;
except
end;
Reg.Free;
//CreatePath
for i := 1 to Length(RegStr) do
if RegStr[i] = '\' then
CreateDir(Copy(RegStr, 1, i));
ShellObject := CreateComObject(CLSID_ShellLink); //ComObj unit, ShlObj unit
ShellLink := ShellObject as IShellLink;
PersistFile := ShellObject as IPersistFile; //ActiveX
with ShellLink do
begin
ParamString := '';
FileName := 'c:\업무보고\aa2008.exe'; //<--여기서 바꾸면 됩니다
WorkingDirectory := ExtractFilePath(FileName);
SetArguments(PChar(ParamString));
SetPath(PChar(FileName));
SetWorkingDirectory(PChar(WorkingDirectory));
RunAs := sw_ShowNormal;
end;
FLinkName := 'MyProgram'; //같은이름의 바로가기이면 덮어쓰거구요 다른이름이면 새로생깁니다
LinkFileName := RegStr + '\' + FLinkName + '.lnk';
PersistFile.Save(PWChar(LinkFileName), False);
end;
<!--CodeE-->