Page 1 of 2

Printing to Network Printer - no dialoge box

Posted: Mon Aug 19, 2019 4:43 pm
by newpie
Hello, I making an app with the goal to print multiple templates in livecode. I made one with macro program before where it could print to designated network label printer (thru app) without installing it and dialog boxes.

Some that code was as so:
SelectedPrinter = idkwvmwprn003\HL65
Run, print.exe /D:\\%SelectedPrinter% "%LocalUser%\Output.txt",,Hide

Can I simulate this in livecode as I can't rely on users installing the designated printers prior to app use? I would like to get away putting in an text file and move to where the print the card or whatever you recommend.

Thanks for any help.

Re: Printing to Network Printer - no dialoge box

Posted: Mon Aug 26, 2019 11:41 pm
by newpie
Hello, any idea on this one?

Re: Printing to Network Printer - no dialoge box

Posted: Tue Aug 27, 2019 3:16 am
by FourthWorld
See the open printing command in the Dictionary, which includes an option for showing the print job dialog.

Re: Printing to Network Printer - no dialoge box

Posted: Fri Aug 30, 2019 3:35 pm
by newpie
Thank you FourthWorld. I wanted to push to the printer without opening the dialogue box actually, like I could in hotkey basically.

Re: Printing to Network Printer - no dialoge box

Posted: Fri Aug 30, 2019 4:40 pm
by FourthWorld
Hmmm.., The print command should normally send to the currently-selected printer without a dialog unless the dialog option is included in the open printing statement.

Is it possible the system did not register that a printer has already been selected, or that it may have changed?

Might be worth a bug report to see how the team views this. Unless the OS now prohibits silent printing, we should expect control over whether the dialog is shown or not.

Re: Printing to Network Printer - no dialoge box

Posted: Sat Aug 31, 2019 12:21 am
by newpie
Ok, I tested the print command for my network printer with the following, but it always select my local printer. Any trick to this? Perhaps I am using wrong command to set printer? Something to note, I do not want the end user to install the printer. Similar to how hotkey could print to any printer on network.

Code: Select all

on mouseUp
   set the printerName to "idkwvmwprn003\HL65"
   print card 1
end mouseUp
Thanks

Re: Printing to Network Printer - no dialoge box

Posted: Sat Aug 31, 2019 1:35 am
by FourthWorld
How is Hotkey configured?

Re: Printing to Network Printer - no dialoge box

Posted: Sat Aug 31, 2019 1:54 am
by newpie
The code is in first post, not any additional configuration code. Is there a way to specify the server address to the network printer in LiveCode?

Re: Printing to Network Printer - no dialoge box

Posted: Mon Sep 02, 2019 12:17 am
by newpie
Hello, if anyone knows how to route to a network printer I took another look and found the full address of network printer is as so:

Code: Select all

idkwvmwprn003.WROK.NET\HL65
I was really hoping to get this working today if possible, any help would be appreciated. thanks.

Re: Printing to Network Printer - no dialoge box

Posted: Mon Sep 02, 2019 3:06 pm
by SparkOut
I don't know, and can't test, but maybe add double backslashes before the printer name, so you are calling it by unc path?

Re: Printing to Network Printer - no dialoge box

Posted: Tue Sep 03, 2019 4:20 pm
by newpie
Thank you SparkOut for your post. I tried the below with no success. It seems to always go to my default printer I noticed.

Code: Select all

on mouseUp
   set the printerName to "idkwvmwprn003\\HL65"
   print card 1
end mouseUp

Code: Select all

on mouseUp
   set the printerName to "idkwvmwprn003.WROK.NET\\HL65"
   print card 1
end mouseUp

Re: Printing to Network Printer - no dialoge box

Posted: Tue Sep 03, 2019 10:20 pm
by SparkOut
I meant \\ before the hostname for the printer, thus:

set the printerName to "\\idkwvmwprn003\HL65"

Re: Printing to Network Printer - no dialoge box

Posted: Tue Sep 03, 2019 10:24 pm
by SparkOut
I can't test properly but there is some magic that can be done with LiveCode using vbscript, so you may be able to test and tweak and adjust the scripts below to achieve something like what you need.
Say you have a button with the following script

Code: Select all

on mouseUp
   --first let's find what printer is currently set as default so that we can
   --override the default and then put it back again afterwards
   put the cGetDefaultPrinter of me into tVBScript
   do tVBScript as "vbscript"
   put the result into tResult
   --answer "The current default printer is" && tResult
   set the cStoredDefaultPrinter of me to tResult
   --now we have saved the current default printer, let's override it with the networked one
   --we get the VBScript which contains placeholder
   put the cSetNetworkPrinter of me into tVBScript
   --this is the hardcoded UNC path to the chosen printer
   put "\\idkwvmwprn003\HL65" into tPrinterName
   --replace the placeholder with the correct printer name
   replace "<~%printernameGoesHere%~>" with tPrinterName in tVBScript
   do tVBScript as "vbscript"
   put the result into tResult
   if tResult is not empty then
      answer "Something went wrong:" && tResult
      --you should handle errors more gracefully than this
      exit to top
   end if
   --try your printing
   print card 1
   --now we can set the original printer back as default
   put the cSetNetworkPrinter of me into tVBScript
   --we got the script with placeholder back
   put the cStoredDefaultPrinter of me into tPrinterName
   --replace the placeholder with the correct printer name stored from before
   replace "<~%printernameGoesHere%~>" with tPrinterName in tVBScript
   do tVBScript as "vbscript"
   put the result into tResult
   if tResult is not empty then
      answer "Something went wrong:" && tResult
      --you should handle errors more gracefully than this
   end if
end mouseUp
The buttons should have custom properties containing the following vbscripts as their values:

cGetDefaultPrinter property should contain

Code: Select all

Set oShell = CreateObject("WScript.Shell")
strValue = "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device"
strPrinter = oShell.RegRead(strValue)
strPrinter = Split(strPrinter, ",")(0)
result = strPrinter
cSetNetworkPrinter property should contain

Code: Select all

Option Explicit
On Error Resume Next
Dim objNetwork, strUNCPrinter,strError,result
strUNCPrinter = "<~%printernameGoesHere%~>"
Set objNetwork = CreateObject("WScript.Network") 
Set objAdd = objNetwork.AddWindowsPrinterConnection(strUNCPrinter)
If Not objAdd Then
    strError = "Error connecting printer"
Else
    objNetwork.SetDefaultPrinter strUNCPrinter
    strError = ""
End If
objNetwork = Nothing
objAdd = Nothing
result = strError

Re: Printing to Network Printer - no dialoge box

Posted: Tue Sep 03, 2019 10:47 pm
by newpie
Thank you SparkOut. My results of using \\ in front did not work, and Livecode still seem to only want to send to the default installed printer.

I saw your second post here, I will test with this now. Thanks again.

Re: Printing to Network Printer - no dialoge box

Posted: Tue Sep 03, 2019 11:11 pm
by newpie
Hello SparkOut, I setup the button as described and it does put my default printer in the cStoredDefaultPrinter custom property. Unfortunately it gives me error "Something went wrong: Error connecting printer" fyi. Wanted to let you know.

I also wanted to make sure i was doing it correctly. When you state something like this
strUNCPrinter = "<~%printernameGoesHere%~>"

you want something to this effect:
strUNCPrinter = "<~%HL65%~>"


Thx