Marco Gasi
asked on
Associating files programatically
Hi all.
I have a small program which I use when I have to restore some file association silently modified by a new program installed. For instance I have recently installed VideoPad and it has associated many video files with itself without prompting for this. The code (working perfectly some time ago) is something like:
Now this code changes the registry values correctly, but avi files are still opened by VideoPad when I double-click on them and the icon is not vlc icon but VideoPad one.
Now, my problem is not to reassociate the avi extension with vlc: I can do it manually. My problem is how to write a program which set the files associations in the registry and makes these associations be respected by Windows. That is, I have to understand why the registry values set by my code above are ignored by Windows.
Hope to have been clear.
Thanks in advance for any advice.
Cheers
Marco
I have a small program which I use when I have to restore some file association silently modified by a new program installed. For instance I have recently installed VideoPad and it has associated many video files with itself without prompting for this. The code (working perfectly some time ago) is something like:
Extension := '.avi';
Prog := 'C:\Program files\VideoLAN\VLC\vlc.exe';
procedure writeAssociation(Extension, Prog: string);
var
reg: TRegistry;
Log: string;
begin
Log := '';
reg := TRegistry.Create;
try
try
reg.RootKey := HKEY_CLASSES_ROOT;
reg.LazyWrite := false;
reg.OpenKey(Extension + '\shell\open\command', true);
reg.WriteString('', Prog + ' %1');
reg.CloseKey;
reg.OpenKey(Extension + '\DefaultIcon', true);
reg.WriteString('', Prog + ',0');
reg.CloseKey;
Log := 'File type ' + Extension + ' is now associated with ' + Prog;
except
Log := 'Association failed for file type ' + Extension;
end;
finally
reg.free;
end;
mmo1.Lines.Add(Log);
end;
Now this code changes the registry values correctly, but avi files are still opened by VideoPad when I double-click on them and the icon is not vlc icon but VideoPad one.
Now, my problem is not to reassociate the avi extension with vlc: I can do it manually. My problem is how to write a program which set the files associations in the registry and makes these associations be respected by Windows. That is, I have to understand why the registry values set by my code above are ignored by Windows.
Hope to have been clear.
Thanks in advance for any advice.
Cheers
Marco
ASKER
Sorry, but i really don't see a solution in the source you posted.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi sinisav, ho do you do? :-)
Yes your code works: I didn't test it yet, but I know beacause I understood that I can simply empty the data of the default value to make the new association work.
Many thanks: you're becoming my personal expert ;-)
Merry Christmas and Happy New Year!
Yes your code works: I didn't test it yet, but I know beacause I understood that I can simply empty the data of the default value to make the new association work.
Many thanks: you're becoming my personal expert ;-)
Merry Christmas and Happy New Year!
ASKER
Merry Christmas and Happy New Year!
Merry Christmas and successful New Year to you, your family and to all who comes to experts-exchange to expand their knowledge or share it as well.
Open in new window
If I look in the registry using regedit it's sure there as it should seem to be but when I right click on a file and select Open With it's not there...So I then added this
Open in new window
Source: http://stackoverflow.com/questions/590892/windows-registry-file-association-menu