Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Associating file extensions using commandline parameters

I am trying to associate two file extensions with my program (an .exe file), lets say that they are ext1 & ext2.

I want to associate ext1 files with my program in a way that if it is shell executed, this commandline (or command) should run\execute:

my_program.exe shell_execute ext1 "<full path of the file>"

Similarly for ext2:

my_program.exe shell_execute ext2 "<full path of the file>"

How do I associate the file extensions to my program?

like image 240
TheDcoder Avatar asked Dec 07 '25 06:12

TheDcoder


1 Answers

Here is a simple file association solution,

; e.g. 
;_FiletypeAssociation('.test', 'test', 'notepad "%1"', 'test description')
;_FiletypeAssociation('.pdf', 'FoxitReader.Document', '"%ProgramFiles%\FoxitReader.exe" "%1"')

Func _FiletypeAssociation($extension, $type, $program, $description = '')
    Local $sHKCR = @OSArch = 'x64' ? 'HKCR64' : 'HKCR'

    $exitcode = RunWait(@ComSpec & ' /c ftype ' & $type & '=' & $program & _
             ' && assoc ' & $extension & '=' & $type, '', @SW_HIDE)
    If $description And Not $exitcode Then
        Return RegWrite($sHKCR & '\' & $type, '', 'Reg_sz', $description)
    EndIf
    Return Not $exitcode
EndFunc
like image 113
Milos Avatar answered Dec 09 '25 20:12

Milos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!