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

问题描述 投票:3回答:1

[我正在尝试将两个文件扩展名与我的程序(.exe文件)相关联,可以说它们分别是ext1ext2

我想以一种方式将ext1文件与我的程序相关联,如果它是外壳执行的,则此命令行(或命令)应运行\执行:

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

类似地ext2

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

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

windows command-line autoit file-association
1个回答
3
投票

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

; 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
© www.soinside.com 2019 - 2024. All rights reserved.