I need to print a nicely formatted (bold and 3 different fonts) page to a remote printer queue with Powershell. Unfortunately I did not find a usable solution for printing. Searching Google, most answers are: create a .html file and print this file with Internet Explorer. My Powershell script runs from an Windows service (a backup software). It seams that Internet Explorer can't be launched from an service, so I cant print the .html file. Powershell is the only scripting language available in this context. Now I search for an solution to print an .html or .xps file from Powershell?
Thanks in advance.
Suggestions:
Have your service...
1 - Try creating a normal scheduled task that looks to a folder where you output the HTML file, and print via a normal PoSH script via the scheduled task.
2 - Create / Register a WMI event that that monitors a folder where you plan to output the html and print similarly via a normal PoSH script
Related
I'm not a native English speaker as such pardon some discrepancy in my question. I'm looking at a way to Automate option selection in Programs/Scripts running via PowerShell.
For example:
Start-Process -FilePath "velociraptor.exe" -ArgumentList "config generate -i"
In the above snipper PowerShell will run Velociraptor and initiate the configuration wizard from a Ps1 file. The Wizard has few options. After running it will generate some Yaml files.
As such what would be the way to have PowerShell Script automate the option selection process? I know what the option should be. I looked around but I don't know proper terms to find what I need. Nor am I sure this can be done with PowerShell.
The end goal is to have the Ps1 download Exe, run the config command and continue with choosing the selection based on predefined choices. So far I gotten download and lunching of the velociraptor.exe working. But not sure how to skip the window in screenshot and have PowerShell script do it instead.
I couldn't find a CLI reference for velociraptor at https://www.velocidex.com/, but, generally speaking, your best bet is to find a non-interactive way to provide the information of interest, via dedicated _parameters_ (possibly pointing to an input file).
Absent that, you can use the following technique to provide successive responses to an external program's interactive prompts, assuming that the program reads the responses from stdin (the standard input stream):
$responses = 'windows', 'foo', 'bar' # List all responses here
$responses | velociraptor.exe config generate -i
I'm trying to write a PowerShell script to send data directly to Zebra GK420d label printer. "Out-Printer" produces endless count of pages and data not being sent to the printer.
Commands:
"data" | Out-Printer "ZDesigner GK420d"
or
Get-Content C:\barcode.txt | Out-Printer "ZDesigner GK420d"
result in producing print job with endless page counting and nothing being printed.
What worked for me was to share Zebra in my network and setting it up as lpt1 port:
net use lpt1: \\host\Zebra
I was able to copy a *.txt file with ZPL contents and it was interpreted correctly by the printer:
copy barcode.txt lpt1
That would work well as a work-around solution, but I'm trying to run this script on a server without admin rights. So sharing a printer or setting lpt1 cannot be done.
I want to be able to send data directly to the printer using PowerShell script, just like it can be done with "Print preferences>Tools>Action>Send command" or in Zebra Setup Utilities > Open Communication With Printer.
Any suggestions will be appreciated.
Inside of the Link-OS SDK there is a .NET SDK. This contains an command line exe which could be used from your script.
http://techdocs.zebra.com/link-os/2-14/pc_net/
Go to the link for "Use the command line"
I added new printer with "Generic \ Text driver" and pointed it to the USB002 port with Zebra printer. I can now use Out-Printer command as intended. Thanks for the answers.
Google provides an example of calling native executables here. The actual "executable" is a .BAT file which calls python. I wanted to see if I could just run a .bat file with some typical OS or maybe even PowerShell commands. According to the help the executable needs to return UTF-8 JSON so I replaced the call to python with the following command:
TYPE %~dp0\SAMPLE.json
Where SAMPLE.json is a UTF-8 file with some JSON content.
Needless to say it does not work:
Error when communicating with the native messaging host.
According to the help it could be because of message size or text vs. binary output modes. I know of no way to get a batch file to "talk binary".
Is there any way to get Chrome to talk to text based CLI utilities like batch files, powershell...?
Im trying to incorporate TexCount into Tex Studio.
Ive gotten the perl script working in the command line, but I would like it done in TexStudio automatically.
I have adapted a bat file, but it doesnt work:
#echo off
C:\texlive\2015\texmf-dist\scripts\texcount\texcount.pl -html -inc "?ame" > "%".html
"%".html
However I tinker with the syntax it doesnt seem to work and at the very most I can get it to produce a blank html file "_count.html"
Can anybody get this .bat file working please?
I've managed to get it working using the TexStudio User Commands.
In the Menus,
Options > Configure TeXStudio
Then,
Build > User Commands
I created my own user command with the name "texcount".
texcount %.tex -inc -total
This runs the texcount script;
on the current file (that's what the % is for),
it includes the files that use \input{},
it provides a total.
I can now run this command from:
Tools > User > (Number of user command: name of user command) e.g. 1:
texcount
Then the results are output in the messages tab.
Hope that helps.
EDIT: To more specifically produce a html file. I imagine you could use the html commands to produce your html file as shown in Thomas' answer.
You could then pipe the output to something like wkhtmltopdf to produce a pdf from the html file and show it using the default TeXstudio pdf viewer.
I could get this to work on my mac, you may need some adjustments for other OSs and/or other directory structures.
I created a script that calls texcount, as follows:
#!/bin/bash
perl /CorrectPath/texcount.pl -v0 -sum -html "$1*" >tempdoc.html
open tempdoc.html
In TexStudio, my user command looks like this:
"/CorrectPath/count_pdf_words.sh" ?ame"
I have a scheduled task set to run on a machine overnight. This task will iterate through a folder printing all the files found therein. I can run the process without issue while logged in however it does not print when run via the scheduled task.
More Info:
The scheduled task executes a powershell script that performs multiple functions such as generating and emailing reports, copying files across network folders and finally printing the contents of a folder. All of these tasks are performed without error if the executing account is currently logged in. If the account is not logged in and run via a scheduled task everything except the printing of Office and PDF documents works correctly (Text documents print fine).
Here is the function I am using to print the documents.
Function Print-File($file)
{
begin
{
function internal-printfile($thefile)
{
if ($thefile -is [string])
{
$filename = $thefile
}
else
{
if ($thefile.FullName -is [string] )
{
$filename = $thefile.FullName
}
}
$start = new-object System.Diagnostics.ProcessStartInfo $filename
$start.Verb = "print"
[System.Diagnostics.Process]::Start($start)
}
if ($file -ne $null)
{
$filespecified = $true;
internal-printfile $file
}
}
process
{
if (!$filespecified)
{
$test = write-Host process ; internal-printfile $_
}
}
}
When running from a scheduled task I can see the process start (Winword or AcroRd32) as I am dumping output to a text file however I do not see anything print. One other difference I noticed is that when I use this function while logged in the Applications other than Adobe reader (Office Apps) start to print the document then close. However when run from a scheduled task the applications do not close on their own.
I would appreciate any feedback, suggestions or pointers at this time as I have hit a wall as far as knowing what else I can check. I would also take suggestions as to an alternative way to accomplish the printing of the files. (NOTE: I cannot predict the file type in the folder)
NOTE: These symptoms are present on two machines, Windows server 2008 and Windows 7, both running Office 2007 and Adobe Reader 10.1.7
I'm trying to do the same thing that you are attempting. I'm pretty sure what you're running into is session 0 isolation. You can read more about it at this MSDN site and this Windows blog post.
I haven't tried the suggestions in the following answer to another question on SO, but it might be worth a try.
Creating Desktop-Folders for session 0
Here is another guy who is trying to print without having a user logged into the machine. There is an answer from someone who claims to know how to do what we're all trying to do, but he doesn't actually post the answer.
Too late for OP, but for future readers... I had the same problem, but with a windows shell .bat file, not PowerShell. As a scheduled task, the script would launch AcroRd32.exe /t, but it wouldn't print anything. Then after a delay, Acrobat was stopped, and the file was moved to the "Printed" folder like everything was good. It printed fine standalone, just not as a scheduled task.
(Background: I'm running Windows 10 x86 on one older computer so that we can use our two bulletproof HP LaserJet 1000 printers. However, the program we used for this in Win 7, batchdocprint, is incompatible with Win 10 and the company is gone. Due to having to learn arcane syntax and workarounds, I've spent way more money in hours getting a few lines of code (below) working right than the program cost, but I couldn't find a suitable replacement. The programs that I found either printed incorrectly, or had options for only one printer.)
The problem for me did seem to be Session 0 isolation blocking GDI+. I went with the seemingly "spammy" suggestion of getting Foxit Reader. It worked, and like Acrobat, the reader is free. I just replaced the path to AcroRd32.exe with the path to FoxitReader.exe
I don't think this will ever be possible with Acrobat Reader. The CLI is not officially supported, so the likelihood of Adobe ever changing it to print without launching the GUI is minimal.
As far as other file types, it depends on what you're using to print them, and whether it can open and print without a GUI. I haven't decided whether to implement this for other common file types so that we can just drag-and-drop, or to keep forcing the users to use the Acrobat PDF printers that are set up to save PDFs in the hot folders. Right now, it's the latter.
My code, for reference, to hopefully save someone else my headache. I only changed/shortened names, and removed duplicate code for the second folder/printer. Note that taskkill requires administrative privileges. Also, you probably need to have a folder named "Printed" in your hot folder, since I don't check for its existence:
#ECHO OFF
REM Monitors folders for PDF's and prints.
REM Use PING for delay - no built-in sleep functionality.
REM Using START backgrounds the process so the script can move on.
:LOOP
cd C:\Hot Folder\
for %%a in ("*.pdf") do (
start "" "C:\Path\To\FoxitReader.exe" /t "C:\Hot Folder\%%a" "HP 1000"
ping 1.1.1.1 -n 2 -w 5000 >NUL
taskkill /IM FoxitReader.exe /F
move /Y "%%a" ".\Printed\%%a")
ping 1.1.1.1 -n 2 -w 5000 >NUL
goto LOOP
Not sure if you ever found the solution to this, but it happens that the printer to be used by task scheduler job should be registered under:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers (local printers)
vs
HKEY_Current_User\Printers\Connections (session printers)