====== Řešení věčného přeregistrovávání DDE ====== Ačkoli se snažím pořád dokola přesvědčovat Windows, aby mi zaregistrovaly příponu .DOC na aplikaci WINWORD.EXE bez DDE, které neúměrně zpomaluje start programů z Office, stále dokola se mi to předělává zpět a položka DDE se imrvére aktivuje. Nevím jak, nevím proč, ale pohár přetekl. Následující prográmek napsaný v C# provede přeregistrování potřebných přípon a odstraní inkriminovanou volbu DDE. Prográmek musíte překompilovat a v metodě Main na konci souboru ještě předtím zkontrolujte, zda cesta k programům WINWORD.EXE, EXCEL.EXE a POWERPNT.EXE je správná. Kompilaci provedete příkazem: csc Soubor.cs Poté program stačí spustit. Není třeba se bát -- program nejdříve zkontroluje, zda asociace již existuje, poté si uloží název asociace a popis a pod stejným názvem provede re-asociaci (to jsou slova). ===== Program ===== /* * Copyright (c) 2004 mentalis.org, MyXaml, Lukas Zapletal * All Rights Reserved * * Licensed under the terms of the GNU General Public License * http://www.gnu.org/licenses/licenses.html#GPL */ using System; using System.Collections.Generic; using System.Text; using System.Collections; using Microsoft.Win32; using System.Security; using DotNetScriptEngine; namespace DotNetScriptEngine { /// List of commands. internal struct CommandList { /// /// Holds the names of the commands. /// public ArrayList Captions; /// /// Holds the commands. /// public ArrayList Commands; } /// Properties of the file association. internal struct FileType { /// /// Holds the command names and the commands. /// public CommandList Commands; /// /// Holds the extension of the file type. /// public string Extension; /// /// Holds the proper name of the file type. /// public string ProperName; /// /// Holds the full name of the file type. /// public string FullName; /// /// Holds the name of the content type of the file type. /// public string ContentType; /// /// Holds the path to the resource with the icon of this file type. /// public string IconPath; /// /// Holds the icon index in the resource file. /// public short IconIndex; } /// Creates file associations for your programs. /// The following example creates a file association for the type XYZ with a non-existent program. ///


VB.NET code
///
    /// Dim FA as New FileAssociation
    /// FA.Extension = "xyz"
    /// FA.ContentType = "application/myprogram"
    /// FA.FullName = "My XYZ Files!"
    /// FA.ProperName = "XYZ File"
    /// FA.AddCommand("open", "C:\mydir\myprog.exe %1")
    /// FA.Create
    /// 
///
C# code
///
    /// FileAssociation FA = new FileAssociation();
    /// FA.Extension = "xyz";
    /// FA.ContentType = "application/myprogram";
    /// FA.FullName = "My XYZ Files!";
    /// FA.ProperName = "XYZ File";
    /// FA.AddCommand("open", "C:\\mydir\\myprog.exe %1");
    /// FA.Create();
    /// 
///
public class FileAssociation { /// Initializes an instance of the FileAssociation class. public FileAssociation() { FileInfo = new FileType(); FileInfo.Commands.Captions = new ArrayList(); FileInfo.Commands.Commands = new ArrayList(); } /// Gets or sets the proper name of the file type. /// A String representing the proper name of the file type. public string ProperName { get { return FileInfo.ProperName; } set { FileInfo.ProperName = value; } } /// Gets or sets the full name of the file type. /// A String representing the full name of the file type. public string FullName { get { return FileInfo.FullName; } set { FileInfo.FullName = value; } } /// Gets or sets the content type of the file type. /// A String representing the content type of the file type. public string ContentType { get { return FileInfo.ContentType; } set { FileInfo.ContentType = value; } } /// Gets or sets the extension of the file type. /// A String representing the extension of the file type. /// If the extension doesn't start with a dot ("."), a dot is automatically added. public string Extension { get { return FileInfo.Extension; } set { if (value.Substring(0, 1) != ".") value = "." + value; FileInfo.Extension = value; } } /// Gets or sets the index of the icon of the file type. /// A short representing the index of the icon of the file type. public short IconIndex { get { return FileInfo.IconIndex; } set { FileInfo.IconIndex = value; } } /// Gets or sets the path of the resource that contains the icon for the file type. /// A String representing the path of the resource that contains the icon for the file type. /// This resource can be an executable or a DLL. public string IconPath { get { return FileInfo.IconPath; } set { FileInfo.IconPath = value; } } /// Adds a new command to the command list. /// The name of the command. /// The command to execute. /// Caption -or- Command is null (VB.NET: Nothing). public void AddCommand(string Caption, string Command) { if (Caption == null || Command == null) throw new ArgumentNullException(); FileInfo.Commands.Captions.Add(Caption); FileInfo.Commands.Commands.Add(Command); } public bool Exists() { RegistryKey RegKey = Registry.ClassesRoot.CreateSubKey(Extension); object obj = RegKey.GetValue(""); return obj != null; } public string CurrentProperName() { if (Extension == null) throw new ArgumentException("Property is not set"); RegistryKey RegKey = Registry.ClassesRoot.CreateSubKey(Extension); return (string)RegKey.GetValue(""); } public string CurrentContentType() { if (Extension == null) throw new ArgumentException("Property is not set"); RegistryKey RegKey = Registry.ClassesRoot.CreateSubKey(Extension); return (string)RegKey.GetValue("Content Type"); } public string CurrentFullName() { if (ProperName == null) throw new ArgumentException("Property is not set"); RegistryKey RegKey = Registry.ClassesRoot.CreateSubKey(ProperName); return (string)RegKey.GetValue(""); } /// Creates the file association. /// Extension -or- ProperName is null (VB.NET: Nothing). /// Extension -or- ProperName is empty. /// The user does not have registry write access. public void Create() { // remove the extension to avoid incompatibilities [such as DDE links] try { Remove(); } catch (ArgumentException) { } // the extension doesn't exist // create the exception if (Extension == "" || ProperName == "") throw new ArgumentException(); int cnt; try { RegistryKey RegKey = Registry.ClassesRoot.CreateSubKey(Extension); RegKey.SetValue("", ProperName); if (ContentType != null && ContentType != "") RegKey.SetValue("Content Type", ContentType); RegKey.Close(); RegKey = Registry.ClassesRoot.CreateSubKey(ProperName); RegKey.SetValue("", FullName); RegKey.Close(); if (IconPath != "") { RegKey = Registry.ClassesRoot.CreateSubKey(ProperName + "\\" + "DefaultIcon"); RegKey.SetValue("", IconPath + "," + IconIndex.ToString()); RegKey.Close(); } for (cnt = 0; cnt < FileInfo.Commands.Captions.Count; cnt++) { RegKey = Registry.ClassesRoot.CreateSubKey(ProperName + "\\" + "Shell" + "\\" + (String)FileInfo.Commands.Captions[cnt]); RegKey = RegKey.CreateSubKey("Command"); RegKey.SetValue("", FileInfo.Commands.Commands[cnt]); RegKey.Close(); } } catch { throw new SecurityException(); } } /// Removes the file association. /// Extension -or- ProperName is null (VB.NET: Nothing). /// Extension -or- ProperName is empty -or- the specified extension doesn't exist. /// The user does not have registry delete access. public void Remove() { if (Extension == null || ProperName == null) throw new ArgumentNullException(); if (Extension == "" || ProperName == "") throw new ArgumentException(); Registry.ClassesRoot.DeleteSubKeyTree(Extension); Registry.ClassesRoot.DeleteSubKeyTree(ProperName); } /// Holds the properties of the file type. private FileType FileInfo; public override string ToString() { return Extension + ", " + ProperName + ", " + FullName; } } } namespace FixAnnoyingOfficeDDE { class Program { static void Register(string ext, string prg) { FileAssociation FA = new FileAssociation(); FA.Extension = ext; if (FA.Exists()) { FA.ProperName = FA.CurrentProperName(); FA.ContentType = FA.CurrentContentType(); FA.FullName = FA.CurrentFullName(); System.Console.WriteLine("Registering " + FA); System.Console.WriteLine(" as " + prg); FA.AddCommand("open", prg); // delete existing association (incl. DDE stuff) and create brand new one FA.Create(); } else { System.Console.WriteLine("The association " + FA.Extension + " did not exist, skipping"); } } static void Main(string[] args) { //Register("txt", @"""c:\Program Files\Vim\vim71\gvim.exe"" ""%1"""); Register("doc", @"""C:\Program Files\Microsoft Office\Office12\WINWORD.EXE"" /n ""%1"""); Register("docx", @"""C:\Program Files\Microsoft Office\Office12\WINWORD.EXE"" /n ""%1"""); Register("dot", @"""C:\Program Files\Microsoft Office\Office12\WINWORD.EXE"" /n ""%1"""); Register("xls", @"""C:\Program Files\Microsoft Office\Office12\EXCEL.EXE"" /e ""%1"""); Register("xlsx", @"""C:\Program Files\Microsoft Office\Office12\EXCEL.EXE"" /e ""%1"""); Register("xlt", @"""C:\Program Files\Microsoft Office\Office12\EXCEL.EXE"" /e ""%1"""); Register("ppt", @"""C:\Program Files\Microsoft Office\Office12\POWERPNT.EXE"" ""%1"""); Register("pptx", @"""C:\Program Files\Microsoft Office\Office12\POWERPNT.EXE"" ""%1"""); } } }
Můžete si také [[http://static.zapletalovi.com/tools/office_fixes/FixAnnoyingOfficeDDE.zip|stáhnout]] ZIP soubor s binárkou, zdrojákem a build baťákem. ~~DISCUSSION~~