0

Asocijacija file extenzije programu

Da bi se asocirao programu njegova extenzija file-a potrebno je dodati nekoliko vrednosti u registry. Naime windows u registry stavlja sve što treba da upamti o tome kakav file format treba da se otvara uz pomoć kog programa. Uz pomoć NSIS-a ovu operaciju može da radi installer na sledeći način.

WriteRegStr HKCR ".mkv" "" "MakeTool.Profile"
WriteRegStr HKCR "MakeTool.Profile" "" "Make Tool Profile"
WriteRegStr HKCR "MakeTool.ProfileDefaultIcon" "" "$INSTDIRMakeTool.exe,0"
WriteRegStr HKCR "MakeTool.Profileshellopencommand" "" '"$INSTDIRMakeTool.exe" "%1"'
System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, i 0, i 0)'

Poslednja linija upadatuje windows. Ikonice profila sada će imati ikonicu programa, tako da na klik će se otvoriti program i učitati profil. Kako bi se prilikom deinstalacije obrisale vrednosti iz Refistry treba napisati sledeće u Uninstall sekciju:

DeleteRegKey HKCR ".mkv"

DeleteRegKey HKCR "MakeTool.Profile"

DeleteRegKey HKCR "MakeTool.ProfileDefaultIcon"

DeleteRegKey HKCR "MakeTool.Profileshellopencommand"

System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, i 0, i 0)'

Ovo radi ako se na početku .nsi file-a navede sledeća definicija variabli

!define SHCNE_ASSOCCHANGED 0x8000000

!define SHCNF_IDLIST 0

Na ovaj način preostali filovi na file sistemu prestaće da budu asocirani sa bilo kojim programom. Uz pomoć Delphija (od čega se može izvesti algoritam za ostale programske jezike) to izgleda na sledeći način:

unit extensionHandling;

interface

uses registry, shlobj;

procedure RegisterFileType(ExtName:String; AppName:String) ;

implementation

procedure RegisterFileType(ExtName:String; AppName:String) ;

var reg:TRegistry;

begin

reg := TRegistry.Create;

try reg.RootKey:=$80000000;

reg.OpenKey('.' + ExtName, True) ;

reg.WriteString('', ExtName + 'file') ;

reg.CloseKey;

reg.CreateKey(ExtName + 'file') ;

reg.OpenKey(ExtName + 'fileDefaultIcon', True) ;

reg.WriteString('', AppName + ',0') ;

reg.CloseKey;

reg.OpenKey(ExtName + 'fileshellopencommand', True) ;

reg.WriteString('',AppName+' "%1"') ;

reg.CloseKey;

finally

reg.Free;

end;

SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil) ;

end;

end.

References:

http://gergo.erdi.hu/blog/2006-10-08-registering_windows_file_types_with_nsis/

http://delphi.about.com/cs/adptips2001/a/bltip0801_3.htm

 

Nikola Milošević

Born in Bratislava, Slovakia, but he lived in Belgrade, Serbia. Now he is doing a PhD in natural language processing at the University of Manchester. Great enthusiast of AI, natural language processing, machine learning, web application security (founder of OWASP local chapter in Serbia, currently one of the leaders of OWASP Manchester chapter and OWASP Seraphimdroid project), open source, mobile and web technologies. Looking forward to create future. Nikola wants to teach machines to feel and understand. Always finding way for dreams to come true.

Twitter LinkedIn Google+ YouTube Xing  

email

Leave a Reply

Your email address will not be published. Required fields are marked *