Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying HTML page 1

Status
Not open for further replies.

JPJeffery

Technical User
May 26, 2006
600
GB
See my 'Supressing ActiveX' - - thread below (no responses yet).

Is there another way of displaying an HTML page or a 'read only' Word doc without said page being prevented from being displayed by the Active Control protection?


JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
You might want to try using the mark of the web.

If your Web page needs to run ActiveX or scripting, you can add a Mark of the Web comment in the HTML code. This Internet Explorer feature allows the HTML files to be forced into a zone other than the Local Machine zone so that they can then run the script or ActiveX code based on the security template that would be applied to the URL identified in the comment. For example if the URL specified was and that URL was present in your trusted sites list, the page would use the security template for the trusted sites zone. This setting works in Internet Explorer 4 and later. To insert a Mark of the Web comment into your HTML file, add one of the following comments:

<!-- saved from url=(0022) -->

You can find more information about this mark through google.

Let us know your results!

X
 
Good stuff. The Mark Of The Web. Who'd have thought it.

Well, Microsoft, obviously...

Ayway, that worked a treat. Now all I've got to do is work out how to get my script to add in the MotW in to a blank line in the html code on the fly.

Thanks, Xaqte!

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
*sigh*

Of course, setting
Code:
"objIE.visible = true"
always helps...

sheesh.

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
OK, it works a treat IF you run the .mht file manually.

The MotW is definitely in the file but when the .mht file is called from the script it doesn't seem to get parsed so we still see the stoopid yellow warning info. bar.

Open up the copy left behind in the temp folder and you get NO yellow warning info bar...

What gives?

Here's the script:
Code:
' Created: 08/10/06 09:29:30 by JefferyJ

Dim objWSHShell
Dim objFSO
Dim objNewsFile
Dim objFlagFile

Dim strNewsFile
Dim strLongFileDate
Dim strShortFileDate
Dim strNewsLastReadFlag
Dim strNewsLastRead
Dim strLatestNews
Dim strLocalSaveName
Dim strLocalTempName
Dim strLine

Const ForReading = 1
Const ForWriting = 2
Const strMotW = "<!-- saved from url=(0019)[URL unfurl="true"]http://www.mno.com/[/URL] -->"

Set objFSO = CreateObject("Scripting.FileSystemObject")
strNewsFile = "\\server\folder\news.doc"
If not objFSO.FileExists(strNewsFile) then
  Set objFSO = Nothing
  wscript.quit
End if

Set objWSHShell = WScript.CreateObject("WScript.Shell")

strTemp = objWSHShell.ExpandEnvironmentStrings("%TEMP%")
strNewsLastReadFlag = strTemp & "\news.flg"
strLocalTempName = strTemp & "\news.tmp"
strLocalSaveName = strTemp & "\news.mht"

If objFSO.FileExists(strLocalTempName) then
  objFSO.DeleteFile(strLocalTempName)
End if
If objFSO.FileExists(strLocalSaveName) then
  objFSO.DeleteFile(strLocalSaveName)
End if


Set objNewsFile = objFSO.GetFile(strNewsFile)
' Get the last modified date of the news file
strLatestNews = cstr(objNewsFile.DateLastModified)

If not objFSO.FileExists(strNewsLastReadFlag) Then
  Set objFlagFile = objFSO.OpenTextFile(strNewsLastReadFlag,ForReading,True) ' Or create the file
End if

Set objFlagFile = objFSO.GetFile(strNewsLastReadFlag) ' 'Bind' to the file (not the same as opening it)
if objFlagFile.Size > 0 then
    Set objFlagFile = objFSO.OpenTextFile(strNewsLastReadFlag,ForReading)
    strNewsLastRead = objFlagFile.ReadLine
    objFlagFile.Close
Else
    strNewsLastRead = "NULL"
End If


call ProcessFlagFile(strNewsLastReadFlag,strNewsLastRead,strLatestNews)

Set objWSHShell = nothing
Set objFSO = nothing
Set objNewsFile = nothing
Set objFlagFile = nothing
Set objWord = nothing
Set objIE = nothing
Set objLocalTempName = nothing
Set objLocalSaveName = nothing

'---------------------------------------------------------
Sub HereIsTheNews()

  Set objWord = CreateObject("Word.Application")
  If Err.Number <> 0 Then
    On Error GoTo 0
    Msg = "MS Word application not found."
    MsgBox Msg,vbExclamation,Msg
    Wscript.Quit
  End If
  On Error GoTo 0

  Set objNewsFile = objWord.Documents.Add(strNewsFile)
  objNewsFile.Activate
  Set objNewsFile = objWord.ActiveDocument
  objNewsFile.SaveAs strLocalTempName, 9
  objNewsFile.close
  objWord.quit
  set objWord = nothing

'-----------------------------------------------------------
' Code to add the Mark Of The Web to the .mht file

Set objLocalTempName = objFSO.OpenTextFile(strLocalTempName,ForReading, False)
Set objLocalSaveName = objFSO.OpenTextFile(strLocalSaveName,ForWriting, True)

Do While Not objLocalTempName.AtEndOfStream
  strLine = RTrim(LTrim(objLocalTempName.ReadLine))
  If Len(strLine) > 0 Then
    objLocalSaveName.WriteLine(strLine)
  Else
    If not eod = 1 then
      objLocalSaveName.WriteLine(strMotW)
      eod = 1
    Else
      objLocalSaveName.WriteLine("")
    end if
  End If
Loop
'-----------------------------------------------------------

Set objIE = CreateObject("InternetExplorer.Application")
  If Err.Number <> 0 Then
    On Error GoTo 0
    Msg = "IE application not found."
    MsgBox Msg,vbExclamation,Msg
    Wscript.Quit
  End If
  On Error GoTo 0

  objIE.visible = true
  objIE.ToolBar = 0
  objIE.Navigate "file://" & strLocalSaveName
End Sub
'-----------------------------------------------------------
Function ProcessFlagFile(strNewsLastReadFlag,strNewsLastRead,strLatestNews)
    If strNewsLastRead = strLatestNews then  ' do nothing apart from clear the objects
      Set objWSHShell = nothing
      Set objFSO = nothing
      Set objNewsFile = nothing
      Set objFlagFile = nothing
      Set objWord = nothing
      Set objIE = nothing
      wscript.quit
    Else 'The date in the flag file doesn't match the last modified date of the news.txt file so reading the news.
      Call HereIsTheNews()
      Set objFlagFile = objFSO.OpenTextFile(strNewsLastReadFlag, ForWriting)
      objFlagFile.write strLatestNews
    End If
End Function

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top