In VBScript I have this:
which will print the file defined in "path". I got a phone call today saying they were unable to print other documents on the printer and had to restart the computer to get it to work. Grasping at straws I need to ask if notepad might still be open and need to be closed?
Code:
'define vars
url = "http://bytes.com"
path = "C:\dev\vbs\temp.txt"
'instantiate
Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
Set fso = CreateObject("Scripting.FileSystemObject")
Set txtfile = fso.OpenTextFile(path, 2, True)
Set oWS = WScript.CreateObject("WScript.Shell")
'make request
xmlhttp.open "GET", url, false
xmlhttp.send ""
'wait for response
xmlhttp.waitForResponse()
'if status is 200, then it's OK
if xmlhttp.status = 200 then
txtfile.WriteLine(xmlhttp.responseText)
txtfile.Close
'enable this to print
oWS.Run "NotePad.exe /p " + path
'enable this to just display
'oWS.Run "notepad.exe " + path
else
'popup bad response, or just omit to end
WScript.Echo("bad response")
end if
'destroy objects. I'm not sure this is necessary
Set txtfile = nothing
Set xmlhttp = nothing
Set oWS = nothing
Set fso = nothing
Comment