uses Shlobj, ActiveX, ComObj;procedure CreateLnk(LnkName:string); var AnObj:IUnknown; ShLink:IShellLink; PFile:IPersistFile; FileName:string; WFileName:WideString; Reg:TRegIniFile; begin //access the two interface of the object AnObj:=CreateComObject(CLSID_ShellLink); ShLink:=Anobj as IShellLink; PFile:=Anobj as IPersistFile; //get the name of the application file FileName:=Paramstr(0); //set the link properties ShLink.SetPath(pchar(FileName)); ShLink.SetWorkingDirectory(PChar(ExtractFilePath(FileName))); //save the file in the current dir //useing a widestring WFileName:=ExtractFilePath(FileName)+LnkName+'.lnk'; PFile.Save(pwchar(WFileName),false); //save on the desktop reg:=TRegIniFile.Create('Software\MicroSoft\Windows\CurrentVersion\explorer'); WFileName:=Reg.ReadString('Shell Folders','Desktop','')+'\'+LnkName+'.lnk'; reg.free; PFile.Save(PWChar(WFileName),false); //save in the start menu reg:=TRegIniFile.Create('Software\MicroSoft\Windows\CurrentVersion\explorer'); WFileName:=Reg.ReadString('Shell Folders','Start Menu','')+'\'+LnkName+'.lnk'; reg.free; PFile.Save(PWChar(WFileName),false); end;
DdeClientConv1.ExecuteMacro(pchar('[CreateGroup(公司名称)]'),False);
DdeClientConv1.ExecuteMacro(pchar('[AddItem("'+Edit1.Text+'\TransOrder.exe",托运单录入软件)]'),false);
var
AnObj:IUnknown;
ShLink:IShellLink;
PFile:IPersistFile;
FileName:string;
WFileName:WideString;
Reg:TRegIniFile;
begin
//access the two interface of the object
AnObj:=CreateComObject(CLSID_ShellLink);
ShLink:=Anobj as IShellLink;
PFile:=Anobj as IPersistFile; //get the name of the application file
FileName:=Paramstr(0);
//set the link properties
ShLink.SetPath(pchar(FileName));
ShLink.SetWorkingDirectory(PChar(ExtractFilePath(FileName)));
//save the file in the current dir
//useing a widestring
WFileName:=ExtractFilePath(FileName)+LnkName+'.lnk';
PFile.Save(pwchar(WFileName),false);
//save on the desktop
reg:=TRegIniFile.Create('Software\MicroSoft\Windows\CurrentVersion\explorer');
WFileName:=Reg.ReadString('Shell Folders','Desktop','')+'\'+LnkName+'.lnk';
reg.free;
PFile.Save(PWChar(WFileName),false);
//save in the start menu
reg:=TRegIniFile.Create('Software\MicroSoft\Windows\CurrentVersion\explorer');
WFileName:=Reg.ReadString('Shell Folders','Start Menu','')+'\'+LnkName+'.lnk';
reg.free;
PFile.Save(PWChar(WFileName),false);
end;