'关联多种文件类型示例
Function GetPath
'' Retrieve path to the script file
Dim path
path = WScript.ScriptFullName '' Script file name
GetPath = Left(path, InstrRev(path, "\")-1)
End Function
Dim WSHShell,APPToLink,CurAPP,APPLength,TypeToLink(3),CurType,TypeLength,HowTo
HowTo = MsgBOX("将要设置Office文件用本目录应用程序打开",vbOKCancel)
IF HowTo = vbOK Then
Set WSHShell = WScript.CreateObject("WScript.Shell")
'循环各应用程序
J=0
Do While J<=UBound(TypeToLink) '不超过数组维数
CurAPP=Trim(Mid(APPToLink,J*APPLength+1,APPLength))
CurType = vbNullString
'以下循环注册各个文件的右键菜单
I=1
Do 'While TypeToLink(J).Length\TypeLength>=I
CurType=Trim(Mid(TypeToLink(J),(I-1)*TypeLength+1,TypeLength))
IF CurType=vbNullString Then Exit Do
WSHShell.RegWrite "HKCR\."&CurType&"\",CurType&"file"
WSHShell.RegWrite "HKCR\"&CurType&"file\DefaultIcon\",Chr(34)&GetPath()&"\"&CurAPP&".EXE"&Chr(34)&",0","REG_EXPAND_SZ"
WSHShell.RegWrite "HKCR\"&CurType&"file\shell\open\command\",Chr(34)&GetPath()&"\"&CurAPP&".EXE"&Chr(34)&SPACE(1)&Chr(34)&"%1"&Chr(34),"REG_SZ"
I=I+1
Loop