$adSaveCreateNotExist = 1
$adSaveCreateOverWrite = 2
$adTypeBinary = 1
$adTypeText = 2
function SaveFileTo($msg,$mhtp){
      $strm=New-Object -ComObject ADODB.Stream
      $Strm.Type = $adTypeText
      $Strm.Charset = "US-ASCII"
      $Strm.Open()
      $dsk=$msg.DataSource
      $Dsk.SaveToObject($Strm, "_Stream")
      
      $strm.SaveToFile($mhtp,$adSaveCreateOverWrite)
}
function createMHT($htmlPath,$mhtPath){
  $objMessage= New-Object -ComObject CDO.Message
  $objMessage.CreateMHTMLBody($htmlPath)
  SaveFileTo $objMessage $mhtPath
}
createMHT "C:\Users\user\Desktop\sampleHtml\free small games.htm" "C:\Users\user\Desktop\sampleHtml\free small games.mht"
Subscribe to:
Post Comments (Atom)
- 
All WMI Class Names list : - Name ...
 - 
Functions are loosely typed in javascript, we are able to pass different types of parameters, too few args, too many argos etc. Keep functio...
 - 
Hi All, Thanks for taking out time to read this post. Can someone help me with this? When I try to run this, System.TypeLoadExeception Error...
 
1 comment:
This works; however, the function leaves the html file locked. I have tried several things to remove the lock from the function without success. These include adding the following to the end of the respective functions:
$Strm.close()
Remove-Variable $Dsk
Remove-Variable $objMessage
Using the SysInternals handle utility, I have verified the powershell has a lock on the html file. There should be some way of clearing the lock. Have you found a way to close the handle on the file programatically through powershell?
Post a Comment