请教!如何删除开始菜单中一个程序快捷方式
请教,开始如何删除开始菜单中的一个程序快捷方式;如下面的形式
C:\Documents and Settings\All Users\「开始」菜单\程序\Microsoft Developer Network
unit Unit3;
interface
uses
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.
[解决办法]
http://dev.csdn.net/develop/article/28/28720.shtm
[解决办法]
先搜索一下就不用浪费100分了,呵呵
[解决办法]
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;
[解决办法]
这个问题我也有遇到了,在删除开始菜单中的文件夹,失败原因说不清楚,如果你直接写路径进去,应该没问题,用这个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);
}
[解决办法]
可以先通过注册表找到开始程序目录所在的位置:HKEY_CURRENT_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders下的Common Programs,然后你可以找到相应的路径,删除快捷方式就可以了
[解决办法]
这个目录下全是快捷方式文件,你删掉相应的就可以了。