Answer the question
In order to leave comments, you need to log in
How to kill a process in VBScript?
WinXP system.
once every 5 minutes WinSCP synchronizes the files and runs this script.
The script enters the folder and sends all the files for printing one by one (in my case they are all pdf).
After copy-pasting, I created the following script
On Error Resume Next
Set gFSO = CreateObject("Scripting.FileSystemObject")
Set gShell = CreateObject("WScript.Shell")
gWatchFolder = "c:\test\"
Set lFolder = gFSO.GetFolder(gWatchFolder)
Set lFiles = lFolder.Files
For Each lFile In lFiles
PrintFile(gWatchFolder & lFile.Name)
Next
Sub PrintFile(pFileName)
WScript.Sleep(5)
s = """C:\Program Files (x86)\Adobe\Reader 10.0\Reader\AcroRd32.exe"" /h /p """ & pFileName & """"
Call gShell.Run(s,0,true)
KillArcobat
gFSO.DeleteFile(pFileName)
End sub
Sub Killacrobat
WScript.Sleep(5)
kill="""c:\windows\system32\taskkill.exe /im acrord32*"""
Call gShell.Run(kill,0,true)
end sub
WScript.Quit
Answer the question
In order to leave comments, you need to log in
The third parameter in gShell.Run(s,0,true) means that the script will wait for the running application to exit, and only then proceed to the execution of the next line of code, (false - the script will continue to run regardless of whether the running application has exited or No).
In the case of Adobe reader, when printing is started from the command line, all windows are closed, except for one, the last one, this is a feature of the reader:
The last command will open a new Adobe Reader window, print the PDF file and then terminate its window unless that window happens to be the only Adobe Reader window left: at least one Adobe Reader window will be left open.
'pinter_PDF.vbs
'Automatically print PDF files that appear in a specific folder
'Install SumatraPDF www.softportal.com/software-7568-sumatra-pdf.html
'Global variables
Set gFSO = CreateObject("Scripting.FileSystemObject")
Set gShell = CreateObject("WScript.Shell")
'Folder where the script waits for PDF files (this folder(s) must be network accessible)
gWatchFolder = "E:\"
'Main Loop
While true
Set lFolder = gFSO.GetFolder(gWatchFolder)
Set lFiles = lFolder.Files
WScript.Sleep(10000)
For Each lFile In lFiles
' msgbox(gWatchFolder)
'msgbox(lFile.Name)
PrintFile(gWatchFolder & lFile.Name)
Next
WEnd
'Function to print a specific pdf file
Sub PrintFile(pFileName)
'Wait some time (until the file is written to the end)
WScript.Sleep(10)
'msgbox(pFileName)
'Specify the path to the SumatraPDF program
s = """C:\Program Files\SumatraPDF\SumatraPDF.exe"" -exit-on-print -print-to-default """ & pFileName & """"
'msgbox(s)
Call gShell.Run( s,0,true)
'msgbox(pFileName)
WScript.Sleep(10)
gFSO.DeleteFile(pFileName)
If gFSO.FileExists(pFileName)
Thenit’s better to let Ivan Ivanovich stop printing than one file goes to the printer many times
msgbox("Failed to delete file " & pFileName & "! Call the geek")
WScript.Quit
'Else
'Not implemented yet
'ToLog("File " & lFileName & " has been deleted.")
End If
End sub
'Finishing someone else's for myself +7 902 44 00 00 6 Geek www.2133790.Ru
'I took the source here https://habrahabr.ru/post/112404/ and thanks to the author for answering my questions
'here autoit-script.ru/index.php?topic= 21264.0
'and from here www.cyberforum.ru/vbscript-wsh/thread1445205.html
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question