views:

370

answers:

3

In Windows Vista (only) when I double click on a file in Windows Explorer that is associated with my application, the following message is displayed:

"Windows cannot find "abc.def". Make sure you typed the name correctly and then try again.

Where abc.def is the file I double click on in Explorer. My app starts if it isn't already running and the file does get opened correctly. Likewise if my app is already running the file is opened correctly. But this error is always displayed.

If instead I use "Open With" and select my app the file opens and no error is displayed.

I've Googled and found various posts from people getting this error with Word, Excel files etc., but no real solution.

A: 

Have you tried setting your app as the default action for that file association? Also try switching between long names and 8.3 names (i.e. progra~1).

tsilb
+1  A: 

Am not sure, but you can use this code under C# to register a file extension to your application. you must run it with administrator privileges

 public class FileRegistrationHelper
    {
        public static void SetFileAssociation(string extension, string progID)
        {
            // Create extension subkey
            SetValue(Registry.ClassesRoot, extension, progID);

            // Create progid subkey
            string assemblyFullPath = System.Reflection.Assembly.GetExecutingAssembly().Location.Replace("/", @"\");
            StringBuilder sbShellEntry = new StringBuilder();
            sbShellEntry.AppendFormat("\"{0}\" \"%1\"", assemblyFullPath);
            SetValue(Registry.ClassesRoot, progID + @"\shell\open\command", sbShellEntry.ToString());
            StringBuilder sbDefaultIconEntry = new StringBuilder();
            sbDefaultIconEntry.AppendFormat("\"{0}\",0", assemblyFullPath);
            SetValue(Registry.ClassesRoot, progID + @"\DefaultIcon", sbDefaultIconEntry.ToString());

            // Create application subkey
            SetValue(Registry.ClassesRoot, @"Applications\" + Path.GetFileName(assemblyFullPath), "", "NoOpenWith");
        }

        private static void SetValue(RegistryKey root, string subKey, object keyValue)
        {
            SetValue(root, subKey, keyValue, null);
        }
        private static void SetValue(RegistryKey root, string subKey, object keyValue, string valueName)
        {
            bool hasSubKey = ((subKey != null) && (subKey.Length > 0));
            RegistryKey key = root;

            try
            {
                if (hasSubKey) key = root.CreateSubKey(subKey);
                key.SetValue(valueName, keyValue);
            }
            finally
            {
                if (hasSubKey && (key != null)) key.Close();
            }
        }
    }

you call it as follows

 string extension = ".def";
            string title = "something here";
            string extensionDescription = "some description";
            FileRegistrationHelper.SetFileAssociation(
              extension, title + "." + extensionDescription);
martani_net
you should also explain how to compile that since he doesnt sound like programmer.
01
well just fire visual studio, put the first part of the code in a cs file, and the second part of the code in the main method!
martani_net
A: 

How long does it take for your app to start? I've also seen this when opening some files that are associated with Visual Studio. (On my system, VS sometimes takes quite a bit of time to launch.)

Reuben