请教,开始如何删除开始菜单中的一个程序快捷方式;如下面的形式
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.
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.
RemoveDirectory(PChar(hPath+'\'+aFolderName));
//删队空目录
但要是Microsoft Developer Network里面有内容,
则想要整个删除Microsoft Developer Network不行,请问,怎么才能删除非空的Microsoft Developer Network
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;
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);
}