请教,开始如何删除开始菜单中的一个程序快捷方式;如下面的形式
C:\Documents and Settings\All Users\「开始」菜单\程序\Microsoft Developer Networkunit Unit3;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,ShlObj,ActiveX, StdCtrls,ShellApi;type
  TForm3 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form3: TForm3;implementation{$R *.dfm}
  procedure   FreePidl(pidl:   PItemIDList);
  var
      allocator:   IMalloc;
  begin
      if   Succeeded(SHGetMalloc(allocator))   then   
      begin   
          allocator.Free(pidl);   
          {$IFDEF   VER100}   
          allocator.Release;   
          {$ENDIF}
      end;   
  end;   
    
  function   CreateFolder(aFolderName:   string;   aLocation:   Integer):   Boolean;   
  var   
      pIdl:   PItemIDList;   
      hPath:   PChar;   
  begin   
      Result   :=   False;
      if   SUCCEEDED(SHGetSpecialFolderLocation(0,   aLocation,   pidl))   then   
      begin   
          hPath   :=   StrAlloc(MAX_PATH);   
          SHGetPathFromIDList(pIdl,   hPath);   
          SetLastError(0);   
          CreateDirectory(PChar(hPath   +   '\\'   +   aFolderName),   nil);   
          if   (GetLastError   =   0)   or   (GetLastError   =   ERROR_ALREADY_EXISTS)   then   
              Result   :=   True;
          FreePIDL(pIdl);   
          StrDispose(hPath);   
      end;   
  end; function  Del_Folder(aFolderName: string; aLocation:Integer;out  Tmp:string):Boolean;
  var
      pIdl:   PItemIDList;
      hPath:   PChar;
      T:TSHFileOpStruct;
      P:String;  begin
      Result   :=   False;
      if   SUCCEEDED(SHGetSpecialFolderLocation(0, aLocation, pidl))   then
      begin
          hPath   :=   StrAlloc(MAX_PATH);
          SHGetPathFromIDList(pIdl,   hPath);
          SetLastError(0);
          P:=hPath;
          with T do
          begin
            Wnd:=0;
            wFunc:=FO_DELETE;
            pFrom:=PChar(P);
            pTo:=nil;
            fFlags:=FOF_ALLOWUNDO+FOF_NOERRORUI;
            hNameMappings:=nil;
            lpszProgressTitle:='正在删除文件夹';
            fAnyOperationsAborted:=False;
          end;
           SHFileOperation(T);
          //RemoveDirectory(PChar(hPath+'\'+aFolderName));//删队空目录          if   (GetLastError   =   0)   then
              Result   :=   True;
          FreePIDL(pIdl);
          StrDispose(hPath);      end;
  end; procedure TForm3.Button1Click(Sender: TObject);
Var
   Tmp:string;
   Re:integer;
begin
      CreateFolder('new',   CSIDL_PROGRAMS);
      Del_Folder('Microsoft Developer Network', CSIDL_PROGRAMS,Tmp);end;
end.

解决方案 »

  1.   

    http://dev.csdn.net/develop/article/28/28720.shtm
      

  2.   

    如果Microsoft Developer Network是空目录,删除快捷方式没问题
    RemoveDirectory(PChar(hPath+'\'+aFolderName));
    //删队空目录
    但要是Microsoft Developer Network里面有内容,
    则想要整个删除Microsoft Developer Network不行,请问,怎么才能删除非空的Microsoft Developer Network
      

  3.   

    uses shellapi;function RemoveDir_ex(dir: string): Boolean;
    var
      sh: TShFileOpStruct;
    begin
      sh.Wnd := handle;
      sh.wFunc := FO_DELETE;
      sh.pFrom := PChar(dir + '*.*' + chr(0));
      sh.pTo := nil;
      sh.fFlags := FOF_NOCONFIRMATION;
      sh.hNameMappings := nil;
      if (ShFileOperation(sh)) <> 0 then
        result := False
      else
        result := true;
    end;
      

  4.   

    这个问题我也有遇到了,在删除开始菜单中的文件夹,失败原因说不清楚,如果你直接写路径进去,应该没问题,用这个SHGetSpecialFolderLocation取出的路径在这里就会失败。可以用注册表里的路径,是可以的。
    TCHAR StarMenu[MAX_PATH] = {0};
    long result;
    HKEY hKey; result = RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"),
    NULL, KEY_QUERY_VALUE, &hKey);
    if(result == ERROR_SUCCESS)

    CRegKey regKey;

    //TCHAR StarMenu[MAX_PATH] = {0};
    DWORD dwLen = MAX_PATH; if(regKey.Open(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"), KEY_READ) == ERROR_SUCCESS)
    {
    regKey.QueryValue(StarMenu, _T("Programs"), &dwLen);
    }
    _tcscat(StarMenu, _T("\\foobar2000"));
    result=RegCloseKey(hKey); 

      

  5.   

    可以先通过注册表找到开始程序目录所在的位置:HKEY_CURRENT_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders下的Common Programs,然后你可以找到相应的路径,删除快捷方式就可以了