uses
ComObj, ActiveX, ShlObj, Registry;
procedure TForm1.Button1Click(Sender: TObject);
var
AnObj: IUnknown;
ShLink: IShellLink;
PFile: IPersistFile;
FileName: string;
WFileName: WideString;
Reg: TRegIniFile;
begin
// 访问对象的两个接口
AnObj := CreateComObject (CLSID_ShellLink);
ShLink := AnObj as IShellLink;
PFile := AnObj as IPersistFile;
// 得到执行程序的完整路径及文件名
filename:=editname.Text;;
// 设置连接的方式属性
ShLink.SetPath (PChar (FileName));
ShLink.SetWorkingDirectory (PChar (
ExtractFilePath (FileName)));
// 存放于当前文件夹
if cbDir.Checked then
begin
// 长字符串
WFileName := ExtractFilePath (FileName) +
extractFilename(filename) + '.lnk';
PFile.Save (PWChar (WFileName), False);
end;
// 存放于桌面上
if cbDesktop.Checked then
begin
Reg := TRegIniFile.Create(
'Software\MicroSoft\Windows\CurrentVersion\Explorer');
WFileName := Reg.ReadString ('Shell Folders', 'Desktop', '') +
'\' + extractFilename(filename)+ '.lnk';
Reg.Free;
PFile.Save (PWChar (WFileName), False);
end;
// 存在开始菜单内
if cbStartMenu.Checked then
begin
Reg := TRegIniFile.Create(
'Software\MicroSoft\Windows\CurrentVersion\Explorer');
WFileName := Reg.ReadString ('Shell Folders', 'Start Menu', '') +
'\' + extractFilename(filename) + '.lnk';
Reg.Free;
PFile.Save (PWChar (WFileName), False);
end;
end;
我用这段代码在桌面建立了快捷方式,但快捷方式的名称只能是该应用程序的名字
我想加一个中文名字,并带参数,不知道如何实现.虽然可以将程序名称改为中文名,但对于已有的程序,却是不能改的,如AutoCAD,它的程序名是acad.exe,改名后就不能执行了,当然它有自己的快捷方式,但我要在它的后面加参数(手工好加),但用上面的代码不知怎样实现?特请教各位大侠!
4 个解决方案
#1
// 存放于桌面上
if cbDesktop.Checked then
begin
Reg := TRegIniFile.Create(
'Software\MicroSoft\Windows\CurrentVersion\Explorer');
WFileName := Reg.ReadString ('Shell Folders', 'Desktop', '') +
'\' + extractFilename(filename)+ '.lnk'; //这里修改不就可以了吗extractFilename(filename)为软件名字,你要怎么改都行
Reg.Free;
PFile.Save (PWChar (WFileName), False);
end;
if cbDesktop.Checked then
begin
Reg := TRegIniFile.Create(
'Software\MicroSoft\Windows\CurrentVersion\Explorer');
WFileName := Reg.ReadString ('Shell Folders', 'Desktop', '') +
'\' + extractFilename(filename)+ '.lnk'; //这里修改不就可以了吗extractFilename(filename)为软件名字,你要怎么改都行
Reg.Free;
PFile.Save (PWChar (WFileName), False);
end;
#2
其他都一样
#3
不行啊,如果我将这里的acad.exe改为"AutoCAD中文版"并带参数(如象在快捷方式的属性里见到的:"C:\Program Files\AutoCAD 2002\acad.exe" /p 用户自定义配置",就不知道怎样实现?
这里的软件名字"extractFilename(filename)"只能是应用程序名(带路径),也就是说,前面的
"C:\Program Files\AutoCAD 2002\acad.exe"是可以的,后面的"/p 用户自定义配置"却加不上去,并且在桌面上显示的是"acad.exe",而不是"AutoCAD中文版"!
这里的软件名字"extractFilename(filename)"只能是应用程序名(带路径),也就是说,前面的
"C:\Program Files\AutoCAD 2002\acad.exe"是可以的,后面的"/p 用户自定义配置"却加不上去,并且在桌面上显示的是"acad.exe",而不是"AutoCAD中文版"!
#4
我已经找到了一个解决办法,过程如下:
//创建快捷方式到桌面
procedure KJFS(StartupFilename,KJFSM:string);
var
tmpObject : IUnknown;
tmpSLink : IShellLink;
tmpPFile : IPersistFile;
PIDL : PItemIDList;
StartupDirectory : array[0..MAX_PATH] of Char;
LinkFilename : WideString;
begin
tmpObject := CreateComObject(CLSID_ShellLink);//创建建立快捷方式的外壳扩展
tmpSLink := tmpObject as IShellLink;//取得接口
tmpPFile := tmpObject as IPersistFile;//用来储存*.lnk文件的接口
tmpSLink.SetPath(pChar(StartupFilename));//设定所在路径
tmpSLink.SetWorkingDirectory(pChar(ExtractFilePath(StartupFilename)));//设定工作目录
SHGetSpecialFolderLocation(0,CSIDL_DESKTOPDIRECTORY,PIDL);//获得桌面的Itemidlist
tmpSLink.SetDescription('');
tmpSLink.SetIconLocation(Pchar(StartupFilename),0);
SHGetPathFromIDList(PIDL,StartupDirectory);//获得桌面路径
LinkFilename := StartupDirectory + KJFSM+'.lnk';
tmpPFile.Save(pWChar(LinkFilename),FALSE);//保存*.lnk文件
end;
//创建快捷方式到桌面
procedure KJFS(StartupFilename,KJFSM:string);
var
tmpObject : IUnknown;
tmpSLink : IShellLink;
tmpPFile : IPersistFile;
PIDL : PItemIDList;
StartupDirectory : array[0..MAX_PATH] of Char;
LinkFilename : WideString;
begin
tmpObject := CreateComObject(CLSID_ShellLink);//创建建立快捷方式的外壳扩展
tmpSLink := tmpObject as IShellLink;//取得接口
tmpPFile := tmpObject as IPersistFile;//用来储存*.lnk文件的接口
tmpSLink.SetPath(pChar(StartupFilename));//设定所在路径
tmpSLink.SetWorkingDirectory(pChar(ExtractFilePath(StartupFilename)));//设定工作目录
SHGetSpecialFolderLocation(0,CSIDL_DESKTOPDIRECTORY,PIDL);//获得桌面的Itemidlist
tmpSLink.SetDescription('');
tmpSLink.SetIconLocation(Pchar(StartupFilename),0);
SHGetPathFromIDList(PIDL,StartupDirectory);//获得桌面路径
LinkFilename := StartupDirectory + KJFSM+'.lnk';
tmpPFile.Save(pWChar(LinkFilename),FALSE);//保存*.lnk文件
end;
#1
// 存放于桌面上
if cbDesktop.Checked then
begin
Reg := TRegIniFile.Create(
'Software\MicroSoft\Windows\CurrentVersion\Explorer');
WFileName := Reg.ReadString ('Shell Folders', 'Desktop', '') +
'\' + extractFilename(filename)+ '.lnk'; //这里修改不就可以了吗extractFilename(filename)为软件名字,你要怎么改都行
Reg.Free;
PFile.Save (PWChar (WFileName), False);
end;
if cbDesktop.Checked then
begin
Reg := TRegIniFile.Create(
'Software\MicroSoft\Windows\CurrentVersion\Explorer');
WFileName := Reg.ReadString ('Shell Folders', 'Desktop', '') +
'\' + extractFilename(filename)+ '.lnk'; //这里修改不就可以了吗extractFilename(filename)为软件名字,你要怎么改都行
Reg.Free;
PFile.Save (PWChar (WFileName), False);
end;
#2
其他都一样
#3
不行啊,如果我将这里的acad.exe改为"AutoCAD中文版"并带参数(如象在快捷方式的属性里见到的:"C:\Program Files\AutoCAD 2002\acad.exe" /p 用户自定义配置",就不知道怎样实现?
这里的软件名字"extractFilename(filename)"只能是应用程序名(带路径),也就是说,前面的
"C:\Program Files\AutoCAD 2002\acad.exe"是可以的,后面的"/p 用户自定义配置"却加不上去,并且在桌面上显示的是"acad.exe",而不是"AutoCAD中文版"!
这里的软件名字"extractFilename(filename)"只能是应用程序名(带路径),也就是说,前面的
"C:\Program Files\AutoCAD 2002\acad.exe"是可以的,后面的"/p 用户自定义配置"却加不上去,并且在桌面上显示的是"acad.exe",而不是"AutoCAD中文版"!
#4
我已经找到了一个解决办法,过程如下:
//创建快捷方式到桌面
procedure KJFS(StartupFilename,KJFSM:string);
var
tmpObject : IUnknown;
tmpSLink : IShellLink;
tmpPFile : IPersistFile;
PIDL : PItemIDList;
StartupDirectory : array[0..MAX_PATH] of Char;
LinkFilename : WideString;
begin
tmpObject := CreateComObject(CLSID_ShellLink);//创建建立快捷方式的外壳扩展
tmpSLink := tmpObject as IShellLink;//取得接口
tmpPFile := tmpObject as IPersistFile;//用来储存*.lnk文件的接口
tmpSLink.SetPath(pChar(StartupFilename));//设定所在路径
tmpSLink.SetWorkingDirectory(pChar(ExtractFilePath(StartupFilename)));//设定工作目录
SHGetSpecialFolderLocation(0,CSIDL_DESKTOPDIRECTORY,PIDL);//获得桌面的Itemidlist
tmpSLink.SetDescription('');
tmpSLink.SetIconLocation(Pchar(StartupFilename),0);
SHGetPathFromIDList(PIDL,StartupDirectory);//获得桌面路径
LinkFilename := StartupDirectory + KJFSM+'.lnk';
tmpPFile.Save(pWChar(LinkFilename),FALSE);//保存*.lnk文件
end;
//创建快捷方式到桌面
procedure KJFS(StartupFilename,KJFSM:string);
var
tmpObject : IUnknown;
tmpSLink : IShellLink;
tmpPFile : IPersistFile;
PIDL : PItemIDList;
StartupDirectory : array[0..MAX_PATH] of Char;
LinkFilename : WideString;
begin
tmpObject := CreateComObject(CLSID_ShellLink);//创建建立快捷方式的外壳扩展
tmpSLink := tmpObject as IShellLink;//取得接口
tmpPFile := tmpObject as IPersistFile;//用来储存*.lnk文件的接口
tmpSLink.SetPath(pChar(StartupFilename));//设定所在路径
tmpSLink.SetWorkingDirectory(pChar(ExtractFilePath(StartupFilename)));//设定工作目录
SHGetSpecialFolderLocation(0,CSIDL_DESKTOPDIRECTORY,PIDL);//获得桌面的Itemidlist
tmpSLink.SetDescription('');
tmpSLink.SetIconLocation(Pchar(StartupFilename),0);
SHGetPathFromIDList(PIDL,StartupDirectory);//获得桌面路径
LinkFilename := StartupDirectory + KJFSM+'.lnk';
tmpPFile.Save(pWChar(LinkFilename),FALSE);//保存*.lnk文件
end;