1

私が見つけた答えはいくつかありますが、特に私の問題を正確に扱っているもの、またはVBSを扱っていないものはありません。

特定のファイル拡張子を指定するときに、既定のプログラムへのフル パスを特定する方法を探しています。

私の最終的な目標は、「.DOC」ファイル (通常は MS Word) を開くプログラムへのショートカットを自動的に作成することです。しかし、これは Windows マシンによって明らかに異なります。

私は次のようなことをしたいと思います:

strDefaultDOCProgram = WshShell.FindAssociatedProgram("doc")

どこ

strDefaultDOCProgram = "C:\Program Files\Microsoft Office 15\root\office15\winword.exe"

たぶん役立つ? Windows 7 に尋ねる - デフォルトでこのファイルを開くプログラム

4

3 に答える 3

2

他の Windows バージョンでこのスクリプトを使用したい場合に備えて、最終的にassocandコマンドを使用することにしました。ftypeここに私が必要とするすべてを行う関数があります。誰かの役に立てば幸いです!

Dim WshShell
Set WshShell = CreateObject("WScript.Shell")

' Should supply the program extension with period "." included
Function GetProgramPath(ext)
Dim strProg, strProgPath

' Get Program Association Handle
Set oExec =  WshShell.Exec("cmd.exe /c assoc " & ext)
strProg = oExec.StdOut.ReadLine()
strProg = Split(strProg, "=")(1)

' Get Path To Program
Set oExec =  WshShell.Exec("cmd.exe /c ftype " & strProg)
strProgPath = oExec.StdOut.ReadLine()
strProgPath = Split(strProgPath, """")(1)

' Return the program path
GetProgramPath = strProgPath

End Function

strPath = GetProgramPath(".doc")
WScript.Echo strPath
于 2013-11-11T15:23:32.887 に答える
1

アソシエイトを使用

assoc /?
Displays or modifies file extension associations

ASSOC [.ext[=[fileType]]]

  .ext      Specifies the file extension to associate the file type with
  fileType  Specifies the file type to associate with the file extension

と ftype

type /?
isplays or modifies file types used in file extension associations

TYPE [fileType[=[openCommandString]]]

 fileType  Specifies the file type to examine or change
 openCommandString Specifies the open command to use when launching files
                   of this type.

お気に入り

assoc .doc
.doc=OpenOffice.org.Doc

ftype OpenOffice.org.Doc
OpenOffice.org.Doc="C:\Program Files\OpenOffice.org 3\program\\swriter.exe" -o "%1"

.Exec でこれらのプログラムを実行するスクリプトを介して。

アップデート:

コマンドからファイル仕様を切り取ります。

>> sCmd = """C:\Program Files\OpenOffice.org 3\program\\swriter.exe"" -o ""%1"""
>> WScript.Echo sCmd
>> WScript.Echo Split(sCmd, """")(1)
>>
"C:\Program Files\OpenOffice.org 3\program\\swriter.exe" -o "%1"
C:\Program Files\OpenOffice.org 3\program\\swriter.exe

更新 II:

.RegRead を使用して、今週のバージョンのレジストリで情報を見つけようとしないでください。assoc と ftype は、オペレーティング システムが問題に対して提供するツールです。

于 2013-11-08T20:22:53.223 に答える