【问题标题】:Associating file extensions using commandline parameters使用命令行参数关联文件扩展名
【发布时间】:2016-06-05 12:51:59
【问题描述】:

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

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

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

同样适用于ext2

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

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

【问题讨论】:

  • 这不是 AutoIt 相关的问题,而是 Windows 注册表问题...所以你应该删除这个标签 ;-)
  • 我正在尝试在 AutoIt 中执行此操作,所以我标记了它:P
  • related(虽然不是原生AutoIt而是cmd,但应该不会太难RunRunWait

标签: windows command-line autoit file-association


【解决方案1】:

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

; 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

【讨论】:

  • 这是我尝试过的:_FiletypeAssociation('.txt', 'htmlfile', '"%ProgramFiles%\Google\Chrome\Application\chrome.exe" "%1"', 'test description')。该脚本以管理权限启动并且似乎工作正常:assoc .txt 给了我.txt=htmlfile。但是,当我双击 txt 文件时,它会使用 Sublime Text(这是我的默认设置)而不是 Chrome 打开。你能解释一下我做错了什么吗?
  • 在 64 位上您可能需要使用 HKCR64。查看更新的代码
  • @johnc.j.: 还要检查ftype htmlfile
猜你喜欢
  • 2015-03-27
  • 1970-01-01
  • 2016-08-23
  • 2020-05-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多