My computer is called "neil" and I want to set some values using WMI in vbScript. I adapetd the script below from one supplied by Microsoft. When I run it in my browser I get
Error Type:
(0x80041003)
/dressage/30/pdf2.asp, line 8
I suspect it is some registry/security setting.
Any advice?
John Lewis
FULL SCRIPT
call Print_HTML_Page("http://neil/dressage/ascii.asp", "ascii")
Sub SetPDFFile(strPDFFile)
Const HKEY_LOCAL_MACHINE = &H80000002
strKeyPath = "SOFTWARE\Dane Prairie Systems\Win2PDF"
strComputer = "."
Set objReg=GetObject( _
"winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
strValueName = "PDFFileName"
objReg.SetExpandedStringValue HKEY_LOCAL_MACHINE,_
strKeyPath,strValueName,strPDFFile
End Sub
Sub Print_HTML_Page(strPathToPage, strPDFFile)
SetPDFFile( strPDFFile )
Set objIE = CreateObject("InternetExplorer.Application")
'From http://www.tek-tips.com/viewthread.cfm?qid=1092473&page=5
On Error Resume Next
strPrintStatus = objIE.QueryStatusWB(6)
If Err.Number 0 Then
MsgBox "Cannot find a printer. Operation aborted."
objIE.Quit
Set objIE = Nothing
Exit Sub
End If
With objIE
.visible=0
.left=200
.top=200
.height=400
.width=400
.menubar=0
.toolbar=1
.statusBar=0
.navigate strPathToPage
End With
'Wait until IE has finished loading
Do while objIE.busy
WScript.Sleep 100
Loop
On Error Goto 0
objIE.ExecWB 6,2
'Wait until IE has finished printing
WScript.Sleep 2000
objIE.Quit
Set objIE = Nothing
End Sub
Update:
Thanks for your reply. The line breaks seem to have been introduced in the process of paasting into this form.
Well spotted - I was using a PDF file name "ascii". I added a .pdf extension but still get the error. I suspect you're right that it's to do with admin rights. Here's more about the setup and what I'm trying to achieve.
Win2pdf is a product for writing PDFs by works by simulating a Windows printer. You "print" the page, select win2pdf in the print dialog and it then asks for a file name. I have it installed on my pc (called Neil) and it works fine in this conventional way.
My aim is to write an html page to a PDF file using win2pdf - but via ASP/vbscript/javascript rather than with manual intervention. The script for doing this was provided by win2PDF's tech support but when it did not work, that was the limit of their understanding.
In the sample script the file ascii.asp just produces a table of ascii codes/characters. The URL given is on my own PC which has IIS set up to run scripts which it does fine. The error I get occurs on about the fourth line executed.
I am logged in with full admin rights - I think! But I'm no expert. I hope this helps to give some more specific suggestions about how to check/fix the admin rights.