In VBScript I have this: -
'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
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?
18 2287
This is a first! Is this the first time you've posted in the ASP forum?
In answer to your question, the last four lines you posted are used to reclaim memory because ASP has no built in garbage collection mechanism, and failing to put those lines in could cause memory leakage. note this line:
This line should close the object that was using notepad, so from the point of view of the server, notepad is done. It sure looks to me like you took care of everything very thoroughly, but it is possible that something prevented notepad from closing for example an error message or a user dialog. And if these interfered with the printing, then that could cause your problem. It seems likely to me that some error or dialog brought on by system settings interfered with the printing and that the error was not caused by the script (which was working up to recently, right?). Give me a while and I can test on my box - notepad should close automatically.
I think I would ask to clear all print jobs, then watch their server when a request comes in.
Jared
@jhardman
(covers insertAlias' eyes) I did do an excellent job, yes.
What happened is I ran this one night, a few times, and it worked well, but the phone call came the next day, which leads me to wonder if that script caused it.
The reason for the script is I have a cash register PC where I want it to check for a generated web page on a schedule and print it. I just set WindowsXP scheduler to run the script every minute.
The only problem I have, right now, is it prints on the default receipt printer instead of the second letter printer. Frinny gave me a link of stuff to read on how to fix that. Haven't done more than glanced at it so if you already know how, I'd appreciate it.
hmm, this script just prints to the default printer. I don't know of a way to change that behavior, but if you could change the default printer for a given application, that might solve the issue. I'm curious though, post Frinny's link here and I'll skim through it, see if I see something obvious.
Jared
OK, try this: - if xmlhttp.status = 200 then
-
'...
-
Dim objNetwork, strUNCPrinter
-
strUNCPrinter = "\\LittleServer\HP office printer"
-
Set objNetwork = CreateObject("WScript.Network")
-
objNetwork.SetDefaultPrinter strUNCPrinter
-
-
oWS.Run "NotePad.exe /p " + path
-
-
strUNCPrinter = "\\cashRegister\receipt printer"
-
objNetwork.SetDefaultPrinter strUNCPrinter
-
else
-
'popup bad response, or just omit to end
-
WScript.Echo("bad response")
-
end if
-
'...
Let me know if this helps, there is still something else I'm going to look up, might give a better solution.
Jared
Take your time. I have to make a roadtrip to try it and it won't be today.
Something I forgot to mention. The receipt printer cannot be interrupted for this printing. It's OK to delay it while the other finishes, though. Also, I'm concerned about changing the default printer for this. If the cash register program wants to print a receipt, will it get messed up as this routine changes it?
Try this variation (specifying the printer to use without changing the default): -
'define vars
-
dim officePrinter
-
officePrinter = "\\server\printer name"
-
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 + " " + officePrinter
-
'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
Cool! I really appreciate it. I'll get down there sometime late tomorrow.
Finally got around to testing this morning. I had to use a network printer but I don't think that makes any difference. The text file it creates is correct but I get this error:
Cannot open the C:\Users\Store\Desktop\temp.txt
\OFFICE\HPOffice.txt file
Make sure a disk is in the drive you specified.
Obviously I changed the location of the file and printer in the script. I can print to that printer from the computer. Perhaps an option is not set right or in the correct place? Haven't looked yet but posting in case someone catches it right away.
I couldn't even get this to print when I removed everything except the print part. Finally it worked when I made '/p' uppercase. When I went back to the complete script and changed it there, I get the same error above.
OK, try this line:
NotePad.exe /p " + path + " " + officePrinter
from the command prompt (where path is the file path and officePrinter is the network address of the printer.
I think you have a stray ". I removed the first one after /p. I get "Not a valid filename" for: NotePad.exe /p + temp.txt + " " + \\OFFICE\HPOffice . This file is on the desktop and I am on the desktop.
This:
appears to work but I don't have an attached printer. I think it gets its first error with the '+'.
@drhowarddrfine
Shouldn't have any pluses in the final version, that is just concatenation left over from the vbscript :
NotePad.exe /p temp.txt \\OFFICE\HPOffice
Cannot open the c:\.....temp.txt \OFFICE\HPOffice.txt file
I give up. I took a Unix box down there and let them use that. I can't continue to use a second box and printer but at least it works. I can't even get a response on a Microsoft newsgroup.
I'll just rewrite my webapp so it supplies a formatted page for the receipt printer and see if that works for them.
@drhowarddrfine
Yeah, if you can't get it to fire from the command line, I would give up too. The only other thing I can think of is possibly check the network name of the printer , which might need to be in quotes. Anyway, sorry I couldn't be more help.
Jared
Found something out. Windows is such a POS that it doesn't allow scripts to print to anything but the default printer!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Tam |
last post by:
I have a problem trying to close a currently running executable.
javaw.exe simply refuses to close. It is in the process list
(confirmed by watching Processes in the task manager) and the code...
|
by: Sagaert Johan |
last post by:
Hi
If i have a form application that creates a thread, is there a way to detect
from within that thread if i have closed the form ?
Now i use the forms closing event to end the thread i...
|
by: Ron |
last post by:
my application is throwing an exception error when closing
if I run a procedure in the app. I can't even trap the
error with try/catch ex As Exception. Is there a way to
completely shut down the...
|
by: Jono |
last post by:
Hello,
I've been getting this message when closing excel (not necessarily when closing the workbook by itself, but when closing Excel and the workbook at the same time):
...
|
by: =?Utf-8?B?UHVjY2E=?= |
last post by:
Hi, I'm using VS2005 and .net 2.0. I'm creating an application that has 3
forms. I want allow users to move forward and backward with the forms and
retain the data users have entered. I thought...
|
by: adamurbas |
last post by:
ya so im pretty much a newb to this whole python thing... its pretty
cool but i just started today and im already having trouble. i
started to use a tutorial that i found somewhere and i followed...
|
by: zacks |
last post by:
If I close and dispose an ODBCConnection object, shouldn't the
connection actually close? I have found that even after closing and
disposing an ODBCConnection, the database it was connected to...
|
by: sewid |
last post by:
Hi there!
I've got a problem with no solution, I hope you might help me.
I am writing a small tool with many buttons. Every button starts a
thread and this thread starts something else, in the...
|
by: dysfunct |
last post by:
I'm running a script that at one point will collect <imgtags from
some html. I've been using the following:
preg_match_all("/<img .*?>/",$html,$images);
and I thought it was working well....
|
by: Wayne |
last post by:
I have had a problem for some time with several databases and figure
there must be a common underlying cause. Sometimes when I open a
database, nothing appears to happen, but an .ldb file gets...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |