Hi, folks!!!

I'm trying to write up an HTA application to do various tasks. I have
included a copy of some code to illustrating one of the things I'm
trying to do. I am to open a PDF report from this HTA script. I have
tried this script on one XP machine with IE6 -- works fine! The other
XP machine with IE7 -- nothin! Both machines have Acrobat Reader
installed.

If I try to open a TXT file using this method I have no problems with
IE6 or IE7.

Does anyone know what gives?!?

===============test.hta===============
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<HTA:Application
border="thin"
borderStyle="normal"
caption="yes"
maximizeButton="no"
minimizeButton="no"
showInTaskbar="yes"
windowState="normal"
innerBorder="yes"
navigable="no"
scroll="no"
scrollFlat="yes"
/>

<script src="VBSlib.vbs" language="VBScript"></script>
<script language="VBScript">
Dim oShell : Set oShell = CreateObject("WScript.Shell")
Dim szCmd : szCmd = Chr(34) & App.Path &"\Report.PDF"""
MsgBox szCmd
oShell.Run szCmd
</script>
</head>
<body>
</body>
</html>
==================================

TIA...

Re: HTA / IE7 question... by Michael

Michael
Fri May 11 19:26:51 CDT 2007

Blue Streak wrote:
> Hi, folks!!!
>
> I'm trying to write up an HTA application to do various tasks. I have
> included a copy of some code to illustrating one of the things I'm
> trying to do. I am to open a PDF report from this HTA script. I have
> tried this script on one XP machine with IE6 -- works fine! The other
> XP machine with IE7 -- nothin! Both machines have Acrobat Reader
> installed.
>
> If I try to open a TXT file using this method I have no problems with
> IE6 or IE7.
>
> Does anyone know what gives?!?
>
> ===============test.hta===============
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> <html>
> <head>
> <meta http-equiv="Content-Type" content="text/html;
> charset=iso-8859-1">
> <HTA:Application
> border="thin"
> borderStyle="normal"
> caption="yes"
> maximizeButton="no"
> minimizeButton="no"
> showInTaskbar="yes"
> windowState="normal"
> innerBorder="yes"
> navigable="no"
> scroll="no"
> scrollFlat="yes"
> />
>
> <script src="VBSlib.vbs" language="VBScript"></script>
> <script language="VBScript">
> Dim oShell : Set oShell = CreateObject("WScript.Shell")
> Dim szCmd : szCmd = Chr(34) & App.Path &"\Report.PDF"""


Where exactly does App.Path come from?


> MsgBox szCmd
> oShell.Run szCmd
> </script>
> </head>
> <body>
> </body>
> </html>
> ==================================
>
> TIA...

--
Michael Harris
Microsoft.MVP.Scripting



Re: HTA / IE7 question... by Blue

Blue
Fri May 11 20:34:46 CDT 2007

Michael Harris (MVP) wrote:

>
> Where exactly does App.Path come from?
>

> Michael Harris
> Microsoft.MVP.Scripting

Forgot about that!!

Here it is:

===========VBSLib.vbs============
'===============================================================================
'Library Name: VBSlib
'Description: Library file containing useful VBScript functions and
constants
'
'Requirements: WSH 5.5 or higher
' Internet Explorer 5.5 or higher
'===============================================================================

'-----Useful Constants-----
'Pop-up dialog
Const vbNoResponse = -1

'FileSystemObject Text Files
Const vbOpenAsASCII = 0
Const vbOpenAsUnicode = -1
Const vbOverwriteIfExist = -1
Const vbFailIfExist = 0
Const vbOpenAsDefault = -2
Const vbCreateIfNotExist = -1
Const vbFailIfNotExist = 0
Const vbForReading = 1
Const vbForWriting = 2
Const vbForAppending = 8

'File Attributes
Const vbFileAttrNormal = 0
Const vbFileAttrReadOnly = 1
Const vbFileAttrHidden = 2
Const vbFileAttrSystem = 4
Const vbFileAttrVolume = 8
Const vbFileAttrDirectory = 16
Const vbFileAttrArchive = 32
Const vbFileAttrAlias = 64
Const vbFileAttrCompressed = 128

'-----Useful Functions / Subroutines-----
Function IsAlpha(szInput)
'Test input for alphabetic characters only
Dim nPos, bValid, nOne
nPos = 1
bValid = False

While nPos <= Len(szInput) AND bValid
nOne = Asc(UCase(Mid(szInput,nPos,1)))

If nOne >= Asc("A") AND nOne <= Asc("Z") Then
bValid = True
End If

nPos = nPos + 1
Wend

IsAlpha = bValid
End Function

Function IsAlphaNum(szInput)
'Test input for alphanumeric characters only
Dim nPos, bValid, nOne
nPos = 1
bValid = False

While nPos <= Len(szInput) AND (bValid = False)
nOne = Asc(UCase(Mid(szInput,nPos,1)))

If (nOne >= Asc("A") AND nOne <= Asc("Z")) OR (nOne >= Asc("0") AND
nOne <= Asc("9")) Then
bValid = True
End If

nPos = nPos + 1
Wend

IsAlphaNum = bValid
End Function

Function IsNothing(objVar)
'VB6 implementation of IsNothing in VBScript
If TypeName(objVar) = "Nothing"Then
IsNothing = True
Else
IsNothing = False
End If
End Function

Function IIf(Expression, TruePart, FalsePart)
'VB6 implementation of Immediate If in VBScript

If Expression = True Then
If IsObject(TruePart) Then
Set IIf = TruePart
Else
IIf = TruePart
End If

Else
If IsObject(FalsePart) Then
Set IIf = FalsePart
Else
IIf = FalsePart
End If

End If

End Function

Class clsApplication
Property Get Path()
If IsObject(WScript) Then
'Windows Scripting Host
Path = Left(WScript.ScriptFullName,
InStr(WScript.ScriptFullName, WScript.ScriptName) - 2)
ElseIf IsObject(window) Then
'Internet Explorer HTML Application (HTA)
szTmp = Replace( Replace(Unescape(window.location),
"file:///", "") ,"/", "\")
Path = Left(szTmp, InstrRev( szTmp , "\") - 1)
End If
End Property
End Class
'=====For App object=====
Dim App : Set App = New clsApplication 'use as App.Path

Function vbIsArray(arr)
'For JS function call
vbIsArray = IsArray(arr)
End Function

Function vbUBound(arr)
'For JS function call
vbUBound = UBound(arr)
End Function

'-----Function used to include this library file-----
'Requirement: VBScript 5.6 (WSH 2.0) or higher
'Description: Returns True if library was loaded successfully
'----------------------------------------------------
'Function Include(sFileSpec)
' On Error Resume Next
'
' With CreateObject("Scripting.FileSystemObject")
' ExecuteGlobal .OpenTextFile(sFileSpec, 1).ReadAll
' Include = (Err.Number = 0)
' End With
'End Function
====================================


Re: HTA / IE7 question... by Blue

Blue
Mon May 14 10:25:35 CDT 2007

On May 11, 9:34 pm, Blue Streak <rdlebre...@hotmail.com> wrote:
> Michael Harris (MVP) wrote:
>
> > Where exactly does App.Path come from?
>
> > Michael Harris
> > Microsoft.MVP.Scripting
>
> Forgot about that!!
>
> Here it is:
>
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3DVBSLib.vbs=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D
> '=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=AD=3D=3D=3D=3D=3D
> 'Library Name: VBSlib
> 'Description: Library file containing useful VBScript functions and
> constants
> '
> 'Requirements: WSH 5.5 or higher
> ' Internet Explorer 5.5 or higher
> '=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=AD=3D=3D=3D=3D=3D
>
> '-----Useful Constants-----
> 'Pop-up dialog
> Const vbNoResponse =3D -1
>
> 'FileSystemObject Text Files
> Const vbOpenAsASCII =3D 0
> Const vbOpenAsUnicode =3D -1
> Const vbOverwriteIfExist =3D -1
> Const vbFailIfExist =3D 0
> Const vbOpenAsDefault =3D -2
> Const vbCreateIfNotExist =3D -1
> Const vbFailIfNotExist =3D 0
> Const vbForReading =3D 1
> Const vbForWriting =3D 2
> Const vbForAppending =3D 8
>
> 'File Attributes
> Const vbFileAttrNormal =3D 0
> Const vbFileAttrReadOnly =3D 1
> Const vbFileAttrHidden =3D 2
> Const vbFileAttrSystem =3D 4
> Const vbFileAttrVolume =3D 8
> Const vbFileAttrDirectory =3D 16
> Const vbFileAttrArchive =3D 32
> Const vbFileAttrAlias =3D 64
> Const vbFileAttrCompressed =3D 128
>
> '-----Useful Functions / Subroutines-----
> Function IsAlpha(szInput)
> 'Test input for alphabetic characters only
> Dim nPos, bValid, nOne
> nPos =3D 1
> bValid =3D False
>
> While nPos <=3D Len(szInput) AND bValid
> nOne =3D Asc(UCase(Mid(szInput,nPos,1)))
>
> If nOne >=3D Asc("A") AND nOne <=3D Asc("Z") Then
> bValid =3D True
> End If
>
> nPos =3D nPos + 1
> Wend
>
> IsAlpha =3D bValid
> End Function
>
> Function IsAlphaNum(szInput)
> 'Test input for alphanumeric characters only
> Dim nPos, bValid, nOne
> nPos =3D 1
> bValid =3D False
>
> While nPos <=3D Len(szInput) AND (bValid =3D False)
> nOne =3D Asc(UCase(Mid(szInput,nPos,1)))
>
> If (nOne >=3D Asc("A") AND nOne <=3D Asc("Z")) OR (nOne =
>=3D Asc("0") AND
> nOne <=3D Asc("9")) Then
> bValid =3D True
> End If
>
> nPos =3D nPos + 1
> Wend
>
> IsAlphaNum =3D bValid
> End Function
>
> Function IsNothing(objVar)
> 'VB6 implementation of IsNothing in VBScript
> If TypeName(objVar) =3D "Nothing"Then
> IsNothing =3D True
> Else
> IsNothing =3D False
> End If
> End Function
>
> Function IIf(Expression, TruePart, FalsePart)
> 'VB6 implementation of Immediate If in VBScript
>
> If Expression =3D True Then
> If IsObject(TruePart) Then
> Set IIf =3D TruePart
> Else
> IIf =3D TruePart
> End If
>
> Else
> If IsObject(FalsePart) Then
> Set IIf =3D FalsePart
> Else
> IIf =3D FalsePart
> End If
>
> End If
>
> End Function
>
> Class clsApplication
> Property Get Path()
> If IsObject(WScript) Then
> 'Windows Scripting Host
> Path =3D Left(WScript.ScriptFullName,
> InStr(WScript.ScriptFullName, WScript.ScriptName) - 2)
> ElseIf IsObject(window) Then
> 'Internet Explorer HTML Application (HTA)
> szTmp =3D Replace( Replace(Unescape(window.location),
> "file:///", "") ,"/", "\")
> Path =3D Left(szTmp, InstrRev( szTmp , "\") - 1)
> End If
> End Property
> End Class
> '=3D=3D=3D=3D=3DFor App object=3D=3D=3D=3D=3D
> Dim App : Set App =3D New clsApplication 'use as App.Path
>
> Function vbIsArray(arr)
> 'For JS function call
> vbIsArray =3D IsArray(arr)
> End Function
>
> Function vbUBound(arr)
> 'For JS function call
> vbUBound =3D UBound(arr)
> End Function
>
> '-----Function used to include this library file-----
> 'Requirement: VBScript 5.6 (WSH 2.0) or higher
> 'Description: Returns True if library was loaded successfully
> '----------------------------------------------------
> 'Function Include(sFileSpec)
> ' On Error Resume Next
> '
> ' With CreateObject("Scripting.FileSystemObject")
> ' ExecuteGlobal .OpenTextFile(sFileSpec, 1).ReadAll
> ' Include =3D (Err.Number =3D 0)
> ' End With
> 'End Function
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

To answer my own question: I was able to open the PDF file by sticking
"explorer" in front of the path of the document. It helps to have
double-quotes around the path.