Exemple #1
0
        public ShellLink(string path)
        {
            this.shellLink = Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("00021401-0000-0000-C000-000000000046"))) as IShellLinkW;
            if (File.Exists(path))
            {
                IntPtr consoleProperties = IntPtr.Zero;
                ((IPersistFile)this.shellLink).Load(path, 0);

                try
                {
                    ((IShellLinkDataList)this.shellLink).CopyDataBlock(0xA0000002, out consoleProperties);
                    this.consoleProperties = (NT_CONSOLE_PROPS)Marshal.PtrToStructure(consoleProperties, typeof(NT_CONSOLE_PROPS));
                }
                catch (Exception)
                {
                }
            }
            else
            {
                ((IPersistFile)this.shellLink).Save(path, true);
            }

            // Initialize default Console Properties (TODO: Fix this bug too)
            if (this.consoleProperties.dwSignature != 0xA0000002)
            {
                this.consoleProperties             = new NT_CONSOLE_PROPS();
                this.consoleProperties.cbSize      = Marshal.SizeOf(this.consoleProperties);
                this.consoleProperties.dwSignature = 0xA0000002;
                this.consoleProperties.ColorTable  = new uint[16];
                for (int i = 0; i < 16; i++)
                {
                    this.consoleProperties.ColorTable[i] = 0xffffffff;
                }
            }
        }
        public ShellLink(string path)
        {
            this.shellLink = Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("00021401-0000-0000-C000-000000000046"))) as IShellLinkW;
            if (File.Exists(path))
            {
                IntPtr consoleProperties = IntPtr.Zero;
                ((IPersistFile)this.shellLink).Load(path, 0);

                try
                {
                    ((IShellLinkDataList)this.shellLink).CopyDataBlock(0xA0000002, out consoleProperties);
                    this.consoleProperties = (NT_CONSOLE_PROPS)Marshal.PtrToStructure(consoleProperties, typeof(NT_CONSOLE_PROPS));
                }
                catch (Exception)
                {
                }
            }
            else
            {
                ((IPersistFile)this.shellLink).Save(path, true);
            }

            // Initialize default Console Properties (TODO: Fix this bug too)
            if (this.consoleProperties.dwSignature != 0xA0000002)
            {
                this.consoleProperties = new NT_CONSOLE_PROPS();
                this.consoleProperties.cbSize = Marshal.SizeOf(this.consoleProperties);
                this.consoleProperties.dwSignature = 0xA0000002;
                this.consoleProperties.ColorTable = new uint[16];
                for (int i = 0; i < 16; i++)
                {
                    this.consoleProperties.ColorTable[i] = 0xffffffff;
                }
            }
        }