Created
July 29, 2014 10:02
-
-
Save ghotz/98003e2e650f878abcc4 to your computer and use it in GitHub Desktop.
Save web page in MHTML format with old technique using CDO and ADODB objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Save to MHTML file | |
# Adapted from http://stackoverflow.com/questions/995339/saving-webpage-as-mhtm-file | |
# | |
# COM SaveOptionsEnum | |
# Const adSaveCreateNotExist = 1 | |
# Const adSaveCreateOverWrite = 2 | |
# | |
# COM StreamTypeEnum | |
# Const adTypeBinary = 1 | |
# Const adTypeText = 2 | |
$SourceURL = "http://www.ghotz.com"; | |
$DestinationFile = "D:\Temp\test.mhtml"; | |
$CDOMessage = New-Object -ComObject CDO.Message; | |
$ADODBStream = New-Object -ComObject ADODB.Stream; | |
$ADODBStream.Type = 2; | |
$ADODBStream.Charset = "US-ASCII"; | |
$ADODBStream.Open(); | |
$CDOMessage.CreateMHTMLBody($SourceURL, 0); | |
$CDOMessage.DataSource.SaveToObject($ADODBStream, "_Stream"); | |
$ADODBStream.SaveToFile($DestinationFile, 2); | |
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($CDOMessage); | |
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($ADODBStream); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment