473,387 Members | 1,295 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Need to closing running app?

drhowarddrfine
7,435 Expert 4TB
In VBScript I have this:
Expand|Select|Wrap|Line Numbers
  1. 'define vars
  2. url = "http://bytes.com" 
  3. path = "C:\dev\vbs\temp.txt"
  4. 'instantiate
  5. Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP") 
  6. Set fso = CreateObject("Scripting.FileSystemObject")
  7. Set txtfile = fso.OpenTextFile(path, 2, True)
  8. Set oWS = WScript.CreateObject("WScript.Shell")
  9. 'make request
  10. xmlhttp.open "GET", url, false 
  11. xmlhttp.send ""
  12. 'wait for response
  13. xmlhttp.waitForResponse()
  14. 'if status is 200, then it's OK
  15. if xmlhttp.status = 200 then
  16.     txtfile.WriteLine(xmlhttp.responseText)
  17.     txtfile.Close
  18.     'enable this to print
  19.     oWS.Run "NotePad.exe /p " + path
  20.     'enable this to just display
  21.     'oWS.Run "notepad.exe " + path    
  22. else
  23.     'popup bad response, or just omit to end
  24.     WScript.Echo("bad response")
  25. end if
  26. 'destroy objects.  I'm not sure this is necessary
  27. Set txtfile = nothing
  28. Set xmlhttp = nothing
  29. Set oWS = nothing
  30. 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?
Dec 9 '08 #1
18 2287
jhardman
3,406 Expert 2GB
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:
Expand|Select|Wrap|Line Numbers
  1. Set oWS = nothing
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
Dec 9 '08 #2
drhowarddrfine
7,435 Expert 4TB
@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.
Dec 9 '08 #3
jhardman
3,406 Expert 2GB
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
Dec 9 '08 #4
drhowarddrfine
7,435 Expert 4TB
That which shall be known, now and forever, as:
Frinny's Link
Dec 9 '08 #5
jhardman
3,406 Expert 2GB
OK, try this:
Expand|Select|Wrap|Line Numbers
  1. if xmlhttp.status = 200 then
  2.     '...
  3.     Dim objNetwork, strUNCPrinter
  4.     strUNCPrinter = "\\LittleServer\HP office printer"
  5.     Set objNetwork = CreateObject("WScript.Network")
  6.     objNetwork.SetDefaultPrinter strUNCPrinter
  7.  
  8.     oWS.Run "NotePad.exe /p " + path
  9.  
  10.     strUNCPrinter = "\\cashRegister\receipt printer"
  11.     objNetwork.SetDefaultPrinter strUNCPrinter
  12. else
  13.     'popup bad response, or just omit to end
  14.     WScript.Echo("bad response")
  15. end if
  16. '...
Let me know if this helps, there is still something else I'm going to look up, might give a better solution.

Jared
Dec 9 '08 #6
drhowarddrfine
7,435 Expert 4TB
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?
Dec 9 '08 #7
jhardman
3,406 Expert 2GB
Try this variation (specifying the printer to use without changing the default):
Expand|Select|Wrap|Line Numbers
  1. 'define vars
  2. dim officePrinter
  3. officePrinter = "\\server\printer name"
  4. url = "http://bytes.com" 
  5. path = "C:\dev\vbs\temp.txt"
  6. 'instantiate
  7. Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP") 
  8. Set fso = CreateObject("Scripting.FileSystemObject")
  9. Set txtfile = fso.OpenTextFile(path, 2, True)
  10. Set oWS = WScript.CreateObject("WScript.Shell")
  11. 'make request
  12. xmlhttp.open "GET", url, false 
  13. xmlhttp.send ""
  14. 'wait for response
  15. xmlhttp.waitForResponse()
  16. 'if status is 200, then it's OK
  17. if xmlhttp.status = 200 then
  18.     txtfile.WriteLine(xmlhttp.responseText)
  19.     txtfile.Close
  20.     'enable this to print
  21.     oWS.Run "NotePad.exe /p " + path + " " + officePrinter
  22.     'enable this to just display
  23.     'oWS.Run "notepad.exe " + path    
  24. else
  25.     'popup bad response, or just omit to end
  26.     WScript.Echo("bad response")
  27. end if
  28. 'destroy objects.  I'm not sure this is necessary
  29. Set txtfile = nothing
  30. Set xmlhttp = nothing
  31. Set oWS = nothing
  32. Set fso = nothing
Dec 9 '08 #8
drhowarddrfine
7,435 Expert 4TB
Cool! I really appreciate it. I'll get down there sometime late tomorrow.
Dec 10 '08 #9
drhowarddrfine
7,435 Expert 4TB
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.
Dec 15 '08 #10
drhowarddrfine
7,435 Expert 4TB
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.
Dec 15 '08 #11
jhardman
3,406 Expert 2GB
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.
Dec 15 '08 #12
drhowarddrfine
7,435 Expert 4TB
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.
Dec 15 '08 #13
drhowarddrfine
7,435 Expert 4TB
This:
Expand|Select|Wrap|Line Numbers
  1. notepad.exe /P temp.txt
appears to work but I don't have an attached printer. I think it gets its first error with the '+'.
Dec 15 '08 #14
jhardman
3,406 Expert 2GB
@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
Dec 16 '08 #15
drhowarddrfine
7,435 Expert 4TB
Cannot open the c:\.....temp.txt \OFFICE\HPOffice.txt file
Dec 16 '08 #16
drhowarddrfine
7,435 Expert 4TB
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.
Dec 16 '08 #17
jhardman
3,406 Expert 2GB
@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
Dec 16 '08 #18
drhowarddrfine
7,435 Expert 4TB
Found something out. Windows is such a POS that it doesn't allow scripts to print to anything but the default printer!
Dec 17 '08 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

0
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...
3
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...
9
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...
0
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): ...
14
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...
12
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...
5
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...
1
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...
1
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....
8
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...
0
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...
0
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...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
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...
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.