2015-01-10 53 views
0

我正在製作兩個HTA應用程序。一個是安裝另一個。下面的代碼是安裝程序HTA中的VBScript,它可以讓計算機識別.sjs擴展名(我創建的擴展名以及與正在安裝的HTA相關的擴展名)。使用.hta文件打開文件

Public Sub Association(EXT, FileType, FileName, Icon) 
Set b = CreateObject("wscript.shell") 
b.regwrite "HKCR\" & EXT & "\", FileType 
b.regwrite "HKCR\" & FileType & "\", "MY file" 
b.regwrite "HKCR\" & FileType & "\DefaultIcon\", Icon 
b.regwrite "HKCR\" & FileType & "\shell\open\command\", FileName & " %L" 
b.regdelete "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & EXT & "\Application" 
b.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & EXT & "\Application", FileName 
b.regdelete "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & EXT & "\OpenWithList\" 
b.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & EXT & "\OpenWithList\a", FileName 
End Sub 
Association ".sjs", "SJS file", "C:\Users\Donald\my_app.hta","C:\Users\Donald\Desktop\my_icon.ico" 

我想它這樣做,當我打開一個.sjs文件時,打開文件C:\用戶\唐納德\ my_app.hta,但這樣它會打開一個對話框,它說「 C:\ Users \ Donald \ Documents \ file.sjs不是有效的Win32應用程序「。我該怎麼做才能按照我的意願去做?

回答

2
  1. 使用On Error Resume Next沒有錯誤檢查是不負責任的。
  2. [Dim ] xxx As Object是無效的VBScript。 (應該是:[Dim ] xxx As yyy強調的是,所有輸入聲明在VBScript中是非法的)

修復了,然後再試一次。使用ftypeassoc檢查註冊表操作的結果。

關於第二個想法:

認爲一個.HTA文件應該/必須以mshta.exe打開。 (應該有一個「明確」的地方,見下文)

更新:

我用isql.hta交互與ADO數據庫工作。參數和語句存儲在.isql文本文件中。因此,試圖模仿你的問題:「我想.isql文件與isql.hta應用程序相關聯;成功證明:雙擊.isql文件打開isql.hta」。所以

assoc .isql=ISQLFile 
.isql=ISQLFile 

ftype ISQLFile="X:\pathto\isql.hta" %* 
ISQLFile="X:\pathto\isql.hta" %* 

Doubleclick => 

--------------------------- 
M:\lib\amfvbs0703\amsinc.isql 
--------------------------- 
M:\lib\amfvbs0703\amsinc.isql is not a valid Win32 application. 
--------------------------- 
OK 
--------------------------- 

M: is a mapped drive; so Windows thinks it's enemy country. 

ftype ISQLFile=c:\WINDOWS\system32\mshta.exe "X:\pathto\isql.hta" %* 
ISQLFile=c:\WINDOWS\system32\mshta.exe "X:\pathto\isql.hta" %* 

Doubleclick => SUCCESS 
+0

我試圖拿走你告訴我改變的兩行(我也編輯了這個問題,這就是爲什麼他們不再是問題了)。現在計算機可以識別.sjs文件,但是當我打開它們時,它仍然會出錯。 –

+0

我不想用另一個程序打開一個.hta而不是mshta.exe,我試圖用.hta打開一個.sjs文件,通常用.exe文件打開其他文件 –

+0

@DonaldDuck - 你還有' xxx as yyy'在Sub定義的參數列表中。 –