2009. szeptember 12., szombat

Delete a shortcut link


Problem/Question/Abstract:

How to delete a shortcut link

Answer:

procedure DeleteShortcut(const
  User {See scUserKey... codes},
  Where {See scWhereKey... codes},
  Name {Name for the shortcut link, w/o ".lnk"}: string);
var
  s: string;
begin
  s := GetEnvVar(scWinDirKey);
  if User <> '' then
    s := s + '\Profiles\' + User
  else if OprSysPlatform = osWinNT then
    raise Exception.CreateFmt('Must have user name to delete shortcut (%s) for NT',
      [Name]);
  if Where = '' then
    raise Exception.CreateFmt('Where must be specified to delete shortcut (%s)',
      [Name]);
  if not DirectoryExists(s) then
    raise Exception.Create('User profile does not exist for ' + User);
  s := s + '\' + Where;
  DeleteFile(s + '\' + Name + '.lnk');
end;

Nincsenek megjegyzések:

Megjegyzés küldése