2
0
Martijn Laan 13 жил өмнө
parent
commit
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,
   WorkingDir, IconFilename: String; const IconIndex, ShowCmd: Integer;
   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 UnregisterTypeLibrary(const Filename: String);
 function UnpinShellLink(const Filename: String): Boolean;
@@ -149,7 +149,7 @@ type
 function CreateShellLink(const Filename, Description, ShortcutTo, Parameters,
   WorkingDir, IconFilename: String; const IconIndex, ShowCmd: Integer;
   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
   HotKey hotkey, which points to ShortcutTo.
   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);
       if OleResult <> S_OK then
         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
         PV.vt := VT_BSTR;
         PV.bstrVal := StringToOleStr(AppUserModelID);
@@ -236,13 +245,6 @@ begin
         if OleResult <> S_OK then
           RaiseOleError('IPropertyStore::SetValue(PKEY_AppUserModel_ExcludeFromShowInNewInstall)', OleResult);
       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;
       if OleResult <> S_OK then
         RaiseOleError('IPropertyStore::Commit', OleResult);