0

I'm making two HTA-applications. One is to install the other one. The code below is the VBScript in the installer HTA which does so that the computer recognises the .sjs extension (an extension which i've created and which has to do with the HTA being installed).

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"

I would like it to do so that when I open a .sjs file, it opens the file C:\Users\Donald\my_app.hta, but like this it opens a dialog box where it says "C:\Users\Donald\Documents\file.sjs isn't a valid Win32 application". How can I do so that it does as I want?

Donald Duck
  • 8,409
  • 22
  • 75
  • 99

1 Answers1

2
  1. Using On Error Resume Next without error check is irresponsible.
  2. [Dim ] xxx As Object isn't valid VBScript. (Should be: [Dim ] xxx As yyy to emphasize that all typed declarations are illegal in VBScript)

Fix that and try again. Use ftype and assoc to check the result of your registry manipulation.

On second thought:

I think that a .HTA file should/must be opened with mshta.exe. (Should have an "explicitly" somewhere; see below)

Update:

I use isql.hta to work with ADO Databases interactively. Parameters and statements are stored in .isql text files. So to tried to mimic your problem with: "I want .isql files associated with the isql.hta application; proof of success: doubleclick on .isql file opens isql.hta". So

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
Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96
  • I tried to take away the 2 lines that you told me to change (I also edited the question, that's why they're not in the question anymore). Now the computer recognises .sjs files, but when I open them, it still does an error. – Donald Duck Jan 10 '15 at 13:08
  • I'm not trying to open a .hta with another program than mshta.exe, I'm trying to open a .sjs with a .hta like you usually open other files with .exe files – Donald Duck Jan 10 '15 at 13:11
  • @DonaldDuck - you still have `xxx AS yyy`'s in the parameter list of the Sub definition. – Ekkehard.Horner Jan 10 '15 at 13:21
  • Where should I insert that code (after having made the changes necessary to make it suitable for my HTA)? – Donald Duck Jan 10 '15 at 14:10
  • @DonaldDuck - use a console to experiment with assoc/ftype (as I did). If/When it works for you, inspect the registry (I hope it will reflect the settings done by assoc/ftype), use the entries to fix your registry manipulations. – Ekkehard.Horner Jan 10 '15 at 14:27