使用命令行参数关联文件扩展名

时间:2016-02-23 15:36:11

标签: windows command-line autoit file-association

我正在尝试将两个文件扩展名与我的程序(.exe文件)相关联,假设它们是ext1& ext2

我希望将ext1文件与我的程序相关联,如果它是shell执行的,这个命令行(或命令)应该运行\ execute:

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

同样适用于ext2

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

如何将文件扩展名与我的程序相关联?

1 个答案:

答案 0 :(得分:2)

这是一个简单的文件关联解决方案,

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

Func _FiletypeAssociation($extension, $type, $program, $description = '')

    $exitcode = RunWait(@ComSpec & ' /c ftype ' & $type & '=' & $program & _
             ' && assoc ' & $extension & '=' & $type, '', @SW_HIDE)
    If $description And Not $exitcode Then
        Return RegWrite('HKCR\' & $type, '', 'Reg_sz', $description)
    EndIf
    Return Not $exitcode
EndFunc
相关问题