views:

439

answers:

1

I use the automation interface of Internet Explorer from Powershell to open a web page in a supported format. I want to save this page back to disk in one of the formats supported by IE. Opening the page is easy:

$ie = New-Object -ComObject "InternetExplorer.Application"
$ie.Navigate("C:\MyFile.mht")

How do I save it back in another format?

I need a solution that does not prompt the user since the idea is to automate this in a script running through multiple files.

+3  A: 

You want to call ExecWB with the appropriate args:

$ie.ExecWB(4,0,$null,[ref]$null)

Explanation of the 4 params:

4 = OLECMDID_SAVEAS
0 = OLECMDEXECOPT_DODEFAULT (This can also be 2 = OLECMDEXECOPT_DONTPROMPTUSER to not prompt and just save)
$null = NULL (I think this can be a path to save to: separate folders with 2 slashes (\\))
[ref]$null = ref NULL :)
John Weldon
Thanks! I can specify filename and extension (filetype) directly in parameter 3. But I still get the dialog box prompt, even when using "2" (DONTPROMPTUSER). That means I can't automate this in a script using multiple files. Do you know a solution to this?
kimsnarf
Apparently ExecWB forces a prompt: http://support.microsoft.com/kb/244757
kimsnarf