mirror of
https://github.com/LorenzCK/OnTopReplica.git
synced 2024-05-20 20:33:06 +12:00
71 lines
2 KiB
C#
71 lines
2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace PostInstaller {
|
|
class Program {
|
|
static int Main(string[] args) {
|
|
#if DEBUG
|
|
foreach(var a in args) {
|
|
Console.Write(a);
|
|
Console.Write(" ");
|
|
}
|
|
Console.WriteLine();
|
|
#endif
|
|
|
|
var success = Run(args);
|
|
|
|
#if DEBUG
|
|
Console.Read();
|
|
#endif
|
|
|
|
return success ? 0 : 1;
|
|
}
|
|
|
|
private static bool Run(string[] args) {
|
|
#if DEBUG
|
|
Console.WriteLine("Attempting to create IShellItem for file {0}...", args[0]);
|
|
#endif
|
|
IShellLink link = (IShellLink)new CShellLink();
|
|
|
|
//Win32Shell.SHCreateItemFromParsingName(args[0], IntPtr.Zero, Win32Shell.IShellLinkId, out link);
|
|
IPersistFile persistFileLink = (IPersistFile)link;
|
|
if (persistFileLink.Load(args[0], 0x00000002L) != 0) {
|
|
Console.WriteLine("Failed to load via IPersistFile.");
|
|
return false;
|
|
}
|
|
|
|
link.Resolve(IntPtr.Zero, 0);
|
|
|
|
#if DEBUG
|
|
Console.WriteLine("Querying for IPropertyStore interface...");
|
|
#endif
|
|
IPropertyStore propStore = (IPropertyStore)link;
|
|
|
|
try {
|
|
#if DEBUG
|
|
Console.WriteLine("Attempting to set property 'System.AppUserModel.ID' to {0}...", args[1]);
|
|
#endif
|
|
|
|
PropertyKey appUserModelKey = new PropertyKey(new Guid("9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3"), 5);
|
|
propStore.SetValue(ref appUserModelKey, new BStrWrapper(args[1]));
|
|
propStore.Commit();
|
|
|
|
//Store
|
|
((IPersistFile)link).Save(args[0], false);
|
|
}
|
|
catch (Exception ex) {
|
|
Console.WriteLine("Unable to set value of AppUserModel.ID property.");
|
|
Console.WriteLine(ex);
|
|
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|