Martijn Laan 13 лет назад
Родитель
Сommit
e04f3142f2
1 измененных файлов с 11 добавлено и 9 удалено
  1. 11 9
      Projects/InstFnc2.pas

+ 11 - 9
Projects/InstFnc2.pas

@@ -18,7 +18,7 @@ interface
 function CreateShellLink(const Filename, Description, ShortcutTo, Parameters,
 function CreateShellLink(const Filename, Description, ShortcutTo, Parameters,
   WorkingDir, IconFilename: String; const IconIndex, ShowCmd: Integer;
   WorkingDir, IconFilename: String; const IconIndex, ShowCmd: Integer;
   const HotKey: Word; FolderShortcut: Boolean; const AppUserModelID: String;
   const HotKey: Word; FolderShortcut: Boolean; const AppUserModelID: String;
-  const ExcludeFromShowInNewInstall: Boolean, const PreventPinning: Boolean): String;
+  const ExcludeFromShowInNewInstall, PreventPinning: Boolean): String;
 procedure RegisterTypeLibrary(const Filename: String);
 procedure RegisterTypeLibrary(const Filename: String);
 procedure UnregisterTypeLibrary(const Filename: String);
 procedure UnregisterTypeLibrary(const Filename: String);
 function UnpinShellLink(const Filename: String): Boolean;
 function UnpinShellLink(const Filename: String): Boolean;
@@ -149,7 +149,7 @@ type
 function CreateShellLink(const Filename, Description, ShortcutTo, Parameters,
 function CreateShellLink(const Filename, Description, ShortcutTo, Parameters,
   WorkingDir, IconFilename: String; const IconIndex, ShowCmd: Integer;
   WorkingDir, IconFilename: String; const IconIndex, ShowCmd: Integer;
   const HotKey: Word; FolderShortcut: Boolean; const AppUserModelID: String;
   const HotKey: Word; FolderShortcut: Boolean; const AppUserModelID: String;
-  const ExcludeFromShowInNewInstall: Boolean, const PreventPinning: Boolean): String;
+  const ExcludeFromShowInNewInstall, PreventPinning: Boolean): String;
 { Creates a lnk file named Filename, with a description of Description, with a
 { Creates a lnk file named Filename, with a description of Description, with a
   HotKey hotkey, which points to ShortcutTo.
   HotKey hotkey, which points to ShortcutTo.
   NOTE! If you want to copy this procedure for use in your own application
   NOTE! If you want to copy this procedure for use in your own application
@@ -216,6 +216,15 @@ begin
       OleResult := SL.QueryInterface(IID_IPropertyStore, PS);
       OleResult := SL.QueryInterface(IID_IPropertyStore, PS);
       if OleResult <> S_OK then
       if OleResult <> S_OK then
         RaiseOleError('IShellLink::QueryInterface(IID_IPropertyStore)', OleResult);
         RaiseOleError('IShellLink::QueryInterface(IID_IPropertyStore)', OleResult);
+      { According to MSDN the PreventPinning property should be set before the ID property. In practice
+        this doesn't seem to matter - at least not for shortcuts - but do it first anyway. }
+      if PreventPinning then begin
+        PV.vt := VT_BOOL;
+        PV.vbool := True;
+        OleResult := PS.SetValue(PKEY_AppUserModel_PreventPinning, PV);
+        if OleResult <> S_OK then
+          RaiseOleError('IPropertyStore::SetValue(PKEY_AppUserModel_PreventPinning)', OleResult);
+      end;
       if (AppUserModelID <> '') then begin
       if (AppUserModelID <> '') then begin
         PV.vt := VT_BSTR;
         PV.vt := VT_BSTR;
         PV.bstrVal := StringToOleStr(AppUserModelID);
         PV.bstrVal := StringToOleStr(AppUserModelID);
@@ -236,13 +245,6 @@ begin
         if OleResult <> S_OK then
         if OleResult <> S_OK then
           RaiseOleError('IPropertyStore::SetValue(PKEY_AppUserModel_ExcludeFromShowInNewInstall)', OleResult);
           RaiseOleError('IPropertyStore::SetValue(PKEY_AppUserModel_ExcludeFromShowInNewInstall)', OleResult);
       end;
       end;
-      if PreventPinning then begin
-        PV.vt := VT_BOOL;
-        PV.vbool := True;
-        OleResult := PS.SetValue(PKEY_AppUserModel_PreventPinning, PV);
-        if OleResult <> S_OK then
-          RaiseOleError('IPropertyStore::SetValue(PKEY_AppUserModel_PreventPinning)', OleResult);
-      end;
       OleResult := PS.Commit;
       OleResult := PS.Commit;
       if OleResult <> S_OK then
       if OleResult <> S_OK then
         RaiseOleError('IPropertyStore::Commit', OleResult);
         RaiseOleError('IPropertyStore::Commit', OleResult);