Command to check the number of pages passed to the printer - windows-xp

I have a batch file that prints a bunch of PDFs, and I want to be able to iterate a command over the amount of pages that the print job has sent to the printer.
Is there a CMD command to pull the page number from a specific print job? If you have a way to do it without a dependency, cool, but if not, oh well. I'll still use it.

You can use wmic command to get needed information via WMI. Using
wmic printjob get
you'll get full information about all print jobs, or
wmic printjob get Caption, TotalPages
to get only a basic info.
For details see http://technet.microsoft.com/en-us/library/cc784189(WS.10).aspx and for more examples see http://www.windows-commandline.com/2011/11/manage-print-jobs-command-line.html

Related

How to find complete list of arguments to use WORD in CLI

I would like to know if it is possible to have all the arguments of the command / exe "winword".
In the official docs the are some examples:
https://support.microsoft.com/en-us/office/command-line-switches-for-microsoft-office-products-079164cd-4ef5-4178-b235-441737deb3a6
But there not all the commands, for example, there is "/mFilePrintDefault" or "/mFileExit"
The objective being to be able to print a pdf without user action.
The Macro Commands are going to vary from one version to the next and of course you can start with your own macro file or use an AutoMacro.
The examples you give are 2 from part of the "Fixed Commands"
There are three lists available but I have no idea which commands function in a specific version as a command line macro, you would need to try them out.
ECMA-376 Office Open XML File Formats [ECMA-376], Fixed commands are here https://learn.microsoft.com/en-us/openspecs/office_standards/ms-oe376/37bf80f7-1d74-47f6-8721-aa077cadca4d
ISO/IEC-29500 Office Open XML File Formats [ISO/IEC-29500:2012], Fixed commands are here
https://learn.microsoft.com/en-us/openspecs/office_standards/ms-oi29500/1ecf33cf-3601-45f0-89fb-0ab824739343
And listed under Basic Types as https://learn.microsoft.com/en-us/openspecs/office_file_formats/ms-doc/e86aecb4-bb67-4de2-9b06-37771115f274
A common example to show using more than one command(s) in sequence is
"path to\winword.exe" "path and filename.docx" /q /n /mFilePrintDefault /mFileExit
But your default printer needs to be a PDF one otherwise your macro needs to more complex

Logging Powershell Job Results

I have created a powershell interface which essentially collects information and then sends that info to an external PS script via Start-Job. I have a timer that triggers recieve-job every second, and updates an output box with STDOUT from the job I created.
External PS Script:
This script has many functions (which utilize many cmdlets), and will be printing messages via Write-Verbose to a log. The issue is, sometimes in these functions I print messages and/or also return a value.
As we all know, anything that a function returns is placed into standard output. So anytime a function returns a value, that value is printed into the Output Rich Textbox control. I don't want that. Also, if I am using VERBOSE, the message is not being printed in the control (however, it is being printed to the console)
What I want:
Print only messages to my rich text box AND my log file, with no function return values in the stream (unless they are apart of a message itself).
Note: I am re-writing this application from a VB.NET app, to a Powershell Studio app... and I noticed previously this was being done by streaming STD Output into the text box, using a similar external powershell script--except that script was using WRITE-HOST. That doesn't make sense to me, as write-host isn't even supposed to be put into the stream.
Alternative Approach:
I had a working example of letting the Job add to the log itself, and then having the UI run Get-Content -tail 1... This WOULD WORK, except that some of my messages will be printed on more than one line, and it wouldn't pull everything as expected. If anyone has a way for me to get any X number of new lines in the log at all times, let me know. That might be easier than my current approach.
so basically you want to use powershell backwards? functions should only return a value that you want in your actual output stream, anything that should not be returning a value to the stream should either be captured in a variable or sent to Out-Null, if want to provide information on what the command is doing that is what write-verbose is for. and Write-Verbose is working as intended, just like write-host it is not put into the stream.
To answer your question what you should do is rewrite your functions so that they return a single value(or no value at all if that is appropriate), for functions that cannot be rewritten you can suppress their output in your script by either assigning them to a variable(if they must be used later) or simply piping them to Out-Null. anything that is currently being captured in the verbose stream that needs to be a part of your output should also be moved to the standard stream and written with Write-Output, potentially with `If statements wrapped around them if you only want that data on certain runs, however if you really want to combine the verbose stream with the standard stream you can check out the info here - Redirect two or more Powershell streams other than output stream to the same file

TFS 2010 Custom Build Process - How to remove CR and LF from WriteBuildMessage stdOutput?

I have an InvokeProcess activity that I am trying to grab the output from (for example):
'sc.exe query w3svc'.
which queries as to whether the IIS service is installed or not.
I am using an Assign activity to try and capture the stdOutput into a variable so I can use it in the next step. The problem is it only captures the first line. The output from this command contains crlfs which I think it the problem. I have tried various ways to remove them but to no avail.
Any ideas on this one?
What I ended up doing was:
1) Moved my command into a batch file and tuned it to return just a more specific result, for example:
sc.exe query w3svc | find /c /i "w3svc"
which returns a 0 or a 1
2) Moved the batch file into source control.
3) Added a DownloadFiles activity to my template and I download the batch right before I need to use it.
4) In the subsequent InvokeProcess I add an Assign to capture the stdOutput and then check that in an If activity after that.
Hope this helps someone as I know there isn't a whole lot on this stuff out there.

How can I find out if an .EXE has Command-Line Options?

Suppose you have an .EXE and you want to check if it has Command-Line Options. How can one know if the .EXE has this ability. In my case I know that Nir Sofers WebBrowserPassView.exe has the ability to start it via cmd.exe and WebBrowserPassView.exe /stext output.txt. But how can I find out if I don't know?
The easiest way would be to use use ProcessExplorer but it would still require some searching.
Make sure your exe is running and open ProcessExplorer.
In ProcessExplorer find the name of your binary file and double click it to show properties.
Click the Strings tab.
Search down the list of string found in the binary file. Most strings will be garbage so they can be ignored. Search for anything that might possibly resemble a command line switch.
Test this switch from the command line and see if it does anything.
Note that it might be your binary simply has no command line switches.
For reference here is the above steps applied to the Chrome executable. The command line switches accepted by Chrome can be seen in the list:
Invoke it from the shell, with an argument like /? or --help. Those are the usual help switches.
Sysinternals has another tool you could use, Strings.exe
Example:
strings.exe c:\windows\system32\wuauclt.exe > %temp%\wuauclt_strings.txt && %temp%\wuauclt_strings.txt
Just use IDA PRO (https://www.hex-rays.com/products/ida/index.shtml) to disassemble the file, and search for some known command line option (using Search...Text) - in that section you will then typically see all the command line options - for the program (LIB2NIST.exe) in the screenshot below, for example, it shows a documented command line option (/COM2TAG) but also some undocumented ones, like /L. Hope this helps?
Really this is an extension to Marcin's answer.
But you could also try passing "rubbish" arguments to see if you get any errors back. Getting any response from the executable directly in the shell will mean that it is likely looking at the arguments you're passing, with an error response being close to a guarantee that it is.
Failing that you might have to directly ask the publishers/creators/owners... sniffing the binaries yourself just seems like far too much work for an end-user.
Unless the writer of the executable has specifically provided a way for you to display a list of all the command line switches that it offers, then there is no way of doing this.
As Marcin suggests, the typical switches for displaying all of the options are either /? or /help (some applications might prefer the Unix-style syntax, -? and -help, respectively). But those are just a common convention.
If those don't work, you're out of luck. You'll need to check the documentation for the application, or perhaps try decompiling the executable (if you know what you're looking for).
This is what I get from console on Windows 10:
C:\>find /?
Searches for a text string in a file or files.
FIND [/V] [/C] [/N] [/I] [/OFF[LINE]] "string" [[drive:][path]filename[ ...]]
/V Displays all lines NOT containing the specified string.
/C Displays only the count of lines containing the string.
/N Displays line numbers with the displayed lines.
/I Ignores the case of characters when searching for the string.
/OFF[LINE] Do not skip files with offline attribute set.
"string" Specifies the text string to find.
[drive:][path]filename
Specifies a file or files to search.
If a path is not specified, FIND searches the text typed at the prompt
or piped from another command.

Powershell - MS Exchange E-mail Autoresponder

We've currently got an issue where we're receiving a lot of bounced e-mails (from an auto generated e-mail) back from people where a specified e-mail address is not valid (failure notice). I need to identify certain messages in the mailbox and respond automatically to them - as a newbie to Powershell I'm struggling a bit! I think I understand how to check for the occurrence of a string but I don't know how to iterate through an inbox to look at/get a handle on each message in turn and I don't know how to extract the subject or body text in order to analyse the contents and perform a string comparison. I fear this should be easy - but I can't find anything on the web that might do the job - can anyone help?
So just to clarify what you're looking for.
Mailbox A receives a large number of failure notice/bounce messages.
You'ld like your powershell script to search Mailbox A for every instance where the Subject line (or message body) contains "String X" and if there is a match, take some action?
Also, what version of Exchange are you using? You need to be at least on 2007 to use Exchange Command Shell. You'll then want to look over the Command Shell commands that can be run.
Look at the Exchange Message Tracking Log, and Pipe the results from one command you run to the next. Think of it like this...
(Run a command) | (Run another command on the results of the first command) | (Run a last command on the results of the second).
You can view an example on my website at:
http://www.technoctopus.com/?p=223
While not exactly the same, it might get you moving in the right direction.