17 12
发新话题
打印

如何创建和删除快捷方式和程序组?

搞到了。谢谢!!!

Windows外壳(Shell)的快捷方式是以OLE技术的组件对象模型
COM(Component Object Modal)为基础而设计的。利用COM模型,一个应用程
序可以调用另一应用程序的某些功能。这方面的技术细节请参阅有关文献。

  在了解了上述基本原理后,创建Windows的快捷方式就比较容易了。首先利
用OLE通过调用CoCreateInstance()函数建立一个IID_IShellLink实例,并同
时得到其接口指针。利用这个接口指针可以对其各项属性进行设置。为了使这
些信息以快捷方式的数据文件(*.lnk)格式保存起来,还需要从IID_IShellLink http://www.cnnic-qd.cn/it/index.html
对象取得其IID_IPersistFile接口指针,以便于调用其成员函数Save()保存前面
设置的信息。
   
  至于如何删除快捷方式以及创建和删除文件夹,则只需要简单地调用文件操作
函数SHFileOperation()就可以了。
  
     另外应该注意,在完成上述操作之后,都要调用SHChangeNotify()函数通
知Windows外壳有关变化以使之及时更新其显示状态。

---------------------------------------------------------------

创建快捷方式
HRESULT CreateLink(LPCSTR lpszPathObj,
            LPSTR lpszPathLink,
            LPSTR lpszDesc)
{
    HRESULT hres;
    IShellLink* psl;
    CoInitialize(NULL);
    // Get a pointer to the IShellLink interface.

http://www.cnnic-qd.cn/it/index.html

    hres = CoCreateInstance(CLSID_ShellLink, NULL,
        CLSCTX_INPROC_SERVER,
        IID_IShellLink,
        (void **)&psl);
   
    if (SUCCEEDED(hres))
    {
        IPersistFile* ppf;
        // Set the path to the shortcut target and add the
        // description.
        psl->SetPath(lpszPathObj);
        psl->SetDescription(lpszDesc);
        // Query IShellLink for the IPersistFile interface for saving the
IT教程:http://www.cnnic-qd.cn/it/index.html

        // shortcut in persistent storage.
    hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf);
            if (SUCCEEDED(hres))
            {
        WORD wsz[MAX_PATH]; // Ensure that the string is ANSI.
        MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1,wsz, MAX_PATH);
        // Save the link by calling IPersistFile::Save.
        hres = ppf->Save(wsz, TRUE);
            ppf->Release();

http://www.cnnic-qd.cn/it/index.html

            }
    psl->Release();
    }
    return hres;
}
Something you can see it. But you can never reach it.

TOP

快捷方式和程序组是文件和目录,直接删除文件和目录即可。

TOP

自己写安装程序?没必要吧?
有inno setup

TOP

function GetSpecialFolderPath(Folder: Integer; CanCreate: Boolean): string;
var
  FilePath: array[0..MAX_PATH] of char;
begin
  { Get path of selected location }
  SHGetSpecialFolderPath(0, FilePath, Folder, CanCreate);
  Result := FilePath;
end;

function CreateShellLink(const AppName, Desc: string; Dest: Integer): string;
{ Creates a shell link for application or document specified in  }
{ AppName with description Desc.  Link will be located in folder }
{ specified by Dest, which is one of the string constants shown  }
{ at the top of this unit.  Returns the full path name of the    }
{ link file. }
var
  SL: IShellLink;
  PF: IPersistFile;
  LnkName: WideString;
begin
  OleCheck(CoCreateInstance(CLSID_ShellLink, nil, CLSCTX_INPROC_SERVER,
    IShellLink, SL));
  { The IShellLink implementer must also support the IPersistFile }
  { interface. Get an interface pointer to it. }
  PF := SL as IPersistFile;
  OleCheck(SL.SetPath(PChar(AppName)));  // set link path to proper file
  if Desc <> '' then
    OleCheck(SL.SetDescription(PChar(Desc))); // set description
  { create a path location and filename for link file }
  LnkName := GetSpecialFolderPath(Dest, True) + '\' +
             ChangeFileExt(AppName, 'lnk');
  PF.Save(PWideChar(LnkName), True);          // save link file
  Result := LnkName;
end;

DelphiX开发人员指南上有详细讲解。
欢迎加入马甲1号粉丝会的二线粉丝会,reika粉丝会。
二线粉丝成员:CodeCoolie,Mzren,5bxb,超级小菜鸟,不知道歪 ,jonssen,Vista,withy

TOP

快捷方式程序组就是文件和目录,自己在相应目录下写就行吧

猜的

TOP

引用:
原帖由 reika 于 2008-2-1 13:39 发表
function GetSpecialFolderPath(Folder: Integer; CanCreate: Boolean): string;
var
  FilePath: array[0..MAX_PATH] of char;
begin
  { Get path of selected location }
  SHGetSpecialFolderPath(0, FileP ...
谢谢会长!
Something you can see it. But you can never reach it.

TOP

引用:
原帖由 hacker47 于 2008-2-1 12:27 发表
自己写安装程序?没必要吧?
有inno setup
666k的卸载程序太过于庞大。
Something you can see it. But you can never reach it.

TOP

 17 12
发新话题