TheDcoder
TheDcoder

Reputation: 539

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?

Upvotes: 3

Views: 304

Answers (1)

Milos
Milos

Reputation: 2946

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

Upvotes: 3

Related Questions