I would like to silent print a PDF file multiple times. I don't really mind what implementation is used, but due to being in a corporate environment I cannot easily install unsupported software :(.
I am currently using the following VBscript but could switch to any other implementation:
TargetFolder = "<path to folder>"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(TargetFolder)
Set colItems = objFolder.Items
For Each objItem In colItems
For i = 1 To 13
objItem.InvokeVerbEx ("Print")
Next
Next
This spools the job 13 times though. Is there a way to do this as a single job?
I also saw a suggestion for printing using adobe reader that looked like this:
AcroRd32.exe /t <file.pdf> <printer_name> <printer_driver> <printer_port>
But I couldn't find any reference material for passing the number of copies as a parameter.
I just found this questions which is essentially the same:
Programatically print multiple copies from command line
It appears that looping through and sending the file multiple times is the only solution without additional software.
Related
We have a vendor who sends us CSV index files to be used with our OnBase document import software. If the CSV file was generated using one of our institutional forms, OnBase ingests them w/o error as we have set up corresponding Document Types that match the 1st delimited value in the CSV file. However, if the CSV file was generated using a vendor form, the 1st delimited value is slightly different and creates OnBase indexing errors. Our vendor uses this CSV format for many of their clients and have indicated it cannot be customized to match our current OnBase Document Types (w/o $$$).
I was tasked with identifying a workaround and found another institution using VBScript to create CSV index files before OnBase processing. After some collaboration, I was able to code a similar approach using VBScript. However, since we already receive index files, our approach identifies how many CSV files are in a target folder, via a loop opens each one, identifies the 1st delimited value within the CSV file, compares that value via a switch case method, updates the 1st delimited CSV value based on the switch case method, then saves the file, until the loop ends (loop value = # of files in target folder - 1...to account for the vbs file). When I click on the vbs file, it works like a charm!
Here is where the trouble begins. If I try and run the vbs file from another vbs file, the script produces errors: File not found. I included some debugging code, and I can see it correctly counts the number of files in the target folder, etc. When I thought it wasn't finding the target folder, I accounted for that by harcoding the path during testing. Even when I am sure it is finding the correct target folder, I'm receiving the same File Not Found error. If I double-click the exact same vbs file, it runs without error and all CSV files are correctly updated.
Update #Ansgar Wiechers resolved the issue of finding and keeping the correct file path value. But, I'm still receiving a File Not Found error at line 163.
Line 163
Char 1
Error: File Not Found
Code: 800A0035
Source: Microsoft VBScript runtime error
On a side note, I've also noticed that my vbs script will only run one time before you have to copy/paste a new instance in the target folder before running it again. Which leads me to think my loop never ended, so I included a debugging MsgBox that displays after the loop has ended (or think it has ended) and right before the WScript.Quit command. These are the last two lines in the script and the message box successfully displays. I'll include code below from both my vbs files.
VBScript file #1 (asterisks masking personal info):
Dim CurrentDirectory
Set FSO = CreateObject("Scripting.FileSystemObject")
CurrentDirectory = "C:\Users\*******\Desktop\ProVerify\Testing\ERROR_FILES\"
FSO.CopyFile "C:\Users\*******\Desktop\ProVerify\Testing\Old Source Files\VBScript_PV_Form_conversion.vbs", CurrentDirectory
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "C:\Users\*******\Desktop\ProVerify\Testing\ERROR_FILES\VBScript_PV_Form_conversion.vbs"
WshShell.Popup "VBS file will be deleted in 10 seconds...", 10
FSO.DeleteFile "C:\Users\*******\Desktop\ProVerify\Testing\ERROR_FILES\VBScript_PV_Form_conversion.vbs"
WScript.Quit
VBScript file #2 (in target folder with CSV files; removed switch case code for this post to save space):
' Declare vars
Dim intDebug, sFile, strDirectory, numFiles, sLine, aLine
intDebug = 1
' Find path of folder where script file resides & Set Object vars
Set objFSO = CreateObject("Scripting.FileSystemObject")
strDirectory = objFSO.GetParentFolderName(WScript.ScriptFullName)
Set objFolder = objFSO.GetFolder(strDirectory)
' Count number of files in folder
numFiles = objFolder.Files.Count - 1
If intDebug = 1 Then
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Popup "File Count: " & numFiles, 2
WshShell.Popup "File Path: " & strDirectory, 2
Else
End If
If numFiles <= 1 Then
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Popup "No Files to Process", 2
WScript.Quit
Else
End If
'Loop through each file in folder
For Each folderIdx In objFolder.Files
Set oStream = folderIdx.OpenAsTextStream
'Read file and capture first delimeted value
sLine = oStream.ReadLine
oStream.Close
aLine = Split(sLine, ",")
' Compare delimeted value & update to OnBase DocType naming convention
Select Case aLine(0)
[*****case method here*****]
End Select
' Create replacement delimited value
sLine = ""
For i = LBound(aLine) To UBound(aLine)
sLine = sLine + aLine(i) + ","
Next
'Open file and replace updated delimeted value
Set oStream = objFSO.OpenTextFile(folderIdx.Name, 2)
oStream.WriteLine Left(sLine, Len(sLine)-1) ' Remove comma from updated delimeted value
oStream.Close
Next
'Reset Object vars
Set oStream = Nothing
Set objFSO = Nothing
Set objFolder = Nothing
If intDebug = 1 Then
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Popup "Conversion Complete", 2
Else
End If
WScript.Quit
In summary:
This code works fine (once) when I double-click; then a new instance needs to be copied/pasted into target folder before double-clicking will run the file again.
Code produces error when run via another vbs file, line 163, File Not Found.
I'm pretty sure this could be accomplished within OnBase, but our OnBase Sys Admin insists I am incorrect. The 51 OnBase User Guides referring to VBScipting over 1,500 times, tells me otherwise. That said, for now I've tasked with finding a solution outside of OnBase. Feel free to comment on this topic, too.
Errors like the one you describe are usually caused by incorrect assumptions about the working directory of a script.
Your folder structure apparently looks somewhat like this (names shortended for brevity):
C:\base\folder
├── ERROR_FILES
│ ├── a.csv
│ ├── b.csv
: :
│ └── second.vbs
└── first.vbs
When you double-click the script second.vbs the working directory is C:\base\folder\ERROR_FILES. However, when you double-click first.vbs the working directory is C:\base\folder. Invoking C:\base\folder\ERROR_FILES\second.vbs from there DOES NOT change the working directory for second.vbs.
Now let's take a look at the code in your second script:
strDirectory = objFSO.GetAbsolutePathName(".")
'***********FOR TESTING ONLY**********************
If strDirectory = "C:\Users\*******\Desktop\ProVerify\Testing" Then
strDirectory = objFSO.GetAbsolutePathName(".") & "\ERROR_FILES"
Else
End If
'***********FOR TESTING ONLY**********************
Set objFolder = objFSO.GetFolder(strDirectory)
...
For Each folderIdx In objFolder.Files
Set oStream = objFSO.OpenTextFile(folderIdx.Name, 1)
...
Next
The "FOR TESTING ONLY" section kind of tries to account for the working directory difference by appending "\ERROR_FILES" to strDirectory, which allows you to enumerate the content of that folder. However, running objFSO.OpenTextFile(folderIdx.Name, 1) still attempts to open each file from the current working directory, which is still C:\base\folder.
To avoid this issue run objFSO.OpenTextFile(folderIdx.Path) or, better yet, use the object's OpenAsTextStream method. Also, when your script is residing in the same folder as your data files it's better to get the directory from the script path rather than appending a particular subfolder to the working directory (which may not be what you think it is).
Change the above code fragment to something like this, and it will do what you want:
strDirectory = objFSO.GetParentFolderName(WScript.ScriptFullName)
Set objFolder = objFSO.GetFolder(strDirectory)
...
For Each folderIdx In objFolder.Files
Set oStream = folderIdx.OpenAsTextStream
...
Next
Use the same approach when you open the file for writing:
Set oStream = folderIdx.OpenAsTextStream(2)
Is there a way to launch two Explorer windows side-by-side (vertically tiled) with a Batch script?
If not, how might I do this with VBS?
I have modified the VBS script above by Hackoo to do exactly what the OP wants...
The comments in the script explain exactly what it will do.
If the two windows don't set into correct position, increase the 'Sleep' time and try again.
If you want a horizontal split, use 'objShell.TileHorizontally'.
Option Explicit
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''' Launches two Explorer windows side-by-side filling the screen dimensions.
''' Minimizes all current open windows before launch; if this is not done,
''' the current open windows will also be resized along with our two windows.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim Calc,AppData,objShell
Calc = "%windir%\system32\calc.exe"
AppData = "%AppData%"
Set objShell = CreateObject("shell.application")
objShell.MinimizeAll
Call Explore(Calc)
WScript.Sleep 800
Call Explore(AppData)
WScript.Sleep 800
objShell.TileVertically
Set objShell = nothing
'*****************************************************
Function Explore(Path)
Dim ws
set ws = CreateObject("wscript.shell")
Explore = ws.run("Explorer /n,/select,"& Path &"")
End Function
'*****************************************************
This might be in the same category as your question. :)
How can a batch file run a program and set the position and size of the window?
Unfortunately it seems that its not possible without any external third part software in batch. Probably easier in VBS - if so the answer should be in the link.
Try this code :
Option Explicit
Dim Calc,AppData
Calc = "%windir%\system32\calc.exe"
AppData = "%AppData%"
Call Explore(Calc)
Call Explore(AppData)
'*****************************************************
Function Explore(Path)
Dim ws
set ws = CreateObject("wscript.shell")
Explore = ws.run("Explorer /n,/select,"& Path &"")
End Function
'*****************************************************
I have a legacy application which doesn't support utilizing the default applications defined in windows which requires that I specify a specific an executable for a file format to be opened within the application. Since Microsoft no longer includes MODI with Office by default I have been looking at using launching Windows Picture Viewer for .TIF, .TIFF, & .BMP files since it is built into Windows; however Microsoft does not have a direct executable for Windows Picture Viewer which can be called forcing me to create a script which executes the command which calls for Windows Picture Viewer to execute. After research the only way I have been able to call the application to open a specific file is by creating a batch file such as below:
GIFTS.BAT
rundll32.exe C:\WINDOWS\system32\shimgvw.dll,ImageView_Fullscreen %~1
If I execute the above code such as GIFTS.BAT "C:\Example Directory\Sample File.tif" from a command prompt or from the application launches and the Sample File.tif opens without a problem; however a command prompt opens along with the file when launching from the application.
Upon which I tried to create a vbscript to hide the batch file from executing however I can't seem to pass my argument if the argument has a "space" within the argument.
GIFTS.VBS
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run """C:\GIFTS.BAT"" " & WScript.Arguments.Item(0), 0
Set WshShell = Nothing
If I try to execute the VBScript from a command prompt such as GIFTS.VBS "C:\Example Directory\Sample File.tif" the application never launches and the command prompt returns no message or error. If I simplify the execute command (removing spaces to GIFTS.VBS "C:\Sample_File.tif" the application launches as well as the file Sample_File.tif is displayed and there is no command prompt displayed when the application executes the VBScript.
My question is how can I pass an argument into the VBS script that in return passes the the batch file when the argument contains spaces (which there is always going to be spaces since the argument will be a file name and path)?
There might be an easier approach to what I want to accomplish; however I am looking for a solution that Windows 7 - 8.1 can utilize with no additional software to install or manage on each workstation. The batch files works great I just need to be able to hide the command prompt that opens along with the application as my end users won't know what to do with it.
Thanks!
Sometimes, nested levels of escaping characters requires intimate knowledge of the undocumented behavior of CMD or some voodoo. Another way to attack the problem is to guarantee that you won't have any spaces in the name of the file. Windows has a concept of a short path (no spaces or special chars) for which every existing file has a unique one.
Here's a modified version of your program for which invoked subcommand doesn't need quotes around the file name.
Set WshShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set fsoFile = fso.GetFile(WScript.Arguments.Item(0))
WshShell.Run """c:\GIFTS.BAT"" " & fsoFile.ShortPath, 0
Set WshShell = Nothing
You may wish to add your own error checking. The specified file must exist in order for the GetFile() command to succeed.
I'm working on setting up Host Scripts for Mokafive player on Windows. I've made a few VBSCripts and have worked with batch files trying to gather information on Mokafive Player start. I'm trying to capture data such as Firewall status, and Encryption status. I've tried multiple variations on gathering this data back to the Mokafive Management Server, such as echoing the results out in VBScrpt, Echoing the results back into the .bat file needed to run the VBScript, with no success.
Does anyone have any code, or examples of a working Host Script for Mokafive Player?
After meeting with several engineers it looks like the VBScript must echo out the results from each condition to an output file. This file will then be read by the launcher XML as a key value pair and parsed out to the database. so per each line that needs to be output you'd use the following...
Set objfs = CreateObject("Scripting.FileSystemObject")
outputfile = "outputfile.out
Set objFile = objfs.CreateTextFile(outputfile,True)
'Your Script Here
objFile.Write "Key=" & "Value" & vbNewLine
I need to check the bitrate of a music file, I need to receive the number in digits like: 192000 (for 192 kbps), 320000 (for 32kbps) or (+)3000000 for wavs and uncompressed music. I mean I need exactly the number, If an MP3 is VBR and is compressed at 194 kbps, I need the 194000 number, not the current CBR 192000.
I was do this job with MEDIAINFO (x64) CLI Program, In Batch:
for /f "tokens=*" %%%% in ('mediainfo "%%a" "--Inform=General;%%BitRate/String%%"') do set "BitRate=%%~%%"
But I have 35.000+ files to check and then the comprobation of all files is more than 2 hours of time.
I need a simple code to check it, Not a program which need to execute it and to waste that lot of time...
Is very important that the code needs to recognize at least this filetypes (I mean the internal bitrate):
AIFF, FLAC, M4A, MP3, OGG, WAV, WMA.
And can't be a code for Ruby or Python, because I'll need to "compile" it and sure when is "compiled" waste a lot of time to check much files (Cause the uncompression of the .exe compiled).
More info: I thinked about store the results in a file and then do a comparision to chek only new added files, But I can't store the result to do a comparision at the next run cause sometimes I'll need to replace checked files (old files). By the way neither I can't handle this by file datestamps. Need to be one unique procediment to check ALL the files, Ever (Or this is what I think...).
I tried another method to check the bitrates, I'm really sure this is what I need but I can't get it run like I want...
This VBS uses the DBPowerAmp program API, And shows a window with info (included the bitrate), But with a window I can't do nothing... Maybe if I can redirect the windows info to a text file... And then set the variable "Bitrate" by reading the bitrate info in the text file... But I don't know how to do that:
' create shell object
Set WshShell = CreateObject("WScript.Shell")
' Create dMC Object
Set dMC = CreateObject("dMCScripting.Converter")
'Read audio properties of a file
Dim AudioProps
AudioProps = dMC.AudioProperties("C:\test.aac")
Call WshShell.Popup(AudioProps, , "Returned Audio Properties", 0)
I've tried to "convert" that code into Batch, like this, But don't run, I get nothing:
#echo off
rundll32.exe dMCScripting.Converter.AudioProperties("C:\Test.aac") > test.txt
exit
Oh and I've tried this too, but waste more time than mediainfo:
mplayer "test.aac" -frames 0 | findstr "kbit"
To give you an idea of what it is like in Ruby, audioinfo is just one of the many libraries doing such things.
require "audioinfo"
AudioInfo.open("R:/mp3/j/John Coltrane - I Think.mp3") do |info|
puts info.to_h
end
=>{"artist"=>"John Coltrane", "album"=>"John Coltrane", "title"=>"I Think", "tracknum"=>nil, "date"=>nil, "length"=>272, "bitrate"=>128}
Here a vbs script, works with mp3, the rest i didn't try
Set objPlayer = CreateObject("WMPlayer.OCX" )
Set colMediaCollection = objPlayer.mediaCollection
Set colMedia = colMediaCollection.getAll()
For i = 0 to colMedia.Count - 1
Set objItem = colMedia.Item(i)
Wscript.Echo objItem.Name & " : " & objItem.GetItemInfo("bitrate")
Next
See http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/OLE~COM~ADO~CDO~ADSI~LDAP+Get~Audio~File~Information.txt for a list of attributes you can use.