直接delefile就可以了
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders 指示了特殊目录的路径,或者用SHGetSpecialFolderPath也可以获取到,下面用注册表的键值写个例子;
function TForm1.deleteShortCut(SCfolder, ShortCutName: string): Integer;
var
lRegedit: TRegistry;
shortCutFullName: string;
begin
Result := -1;
if (trim(SCfolder) = '') or (Trim(ShortCutName) = '') then
begin
Exit;
end;
lRegedit := TRegistry.Create();
lRegedit.RootKey := HKEY_CURRENT_USER;
if lRegedit.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders', False) then
begin
shortCutFullName := IncludeTrailingPathDelimiter(lRegedit.ReadString(trim(SCfolder))) + trim(ShortCutName) + '.lnk';
if FileExists(shortCutFullName) then
begin
Result := 0;
if DeleteFile(shortCutFullName) then
begin
Result := 1;
end;
end;
end;
lRegedit.Free();
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
case deleteShortCut('Desktop', '快捷方式名字') of
//
-1:
begin
Self.Caption := ' key or file not exist';
end;
0:
begin
Self.Caption := 'delete fail';
end;
1:
begin
Self.Caption := 'success';
end;
else
Self.Caption
:= 'Oh My GOD!';
end;
end;
[[it] 本帖最后由 anthony634 于 2008-10-8 10:51 编辑 [/it]]