Hot Topic (More than 10 Replies) Printer Dialog Box or Printer Strings from OS (Read 3294 times)
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Printer Dialog Box or Printer Strings from OS
Feb 20th, 2009 at 8:59pm
Print Post Print Post  
Is there a way to get the a string of available printers from operating system and incorporating it in Sesame code or even better yet, ability to display standard print dialog before printing... by incorporating it into sesame code?  If so, how?

I probably can make string and display it through combobox but wondering if there is a way to take it directly from operating system, so I do not have to manually maintain that string.

Your help will be very much appreciated. Thanks.
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Printer Dialog Box or Printer Strings from OS
Reply #1 - Feb 20th, 2009 at 9:59pm
Print Post Print Post  
If you are on XP or higher, there is a command line tool that lets you work with printers. Sesame can invoke this tool and receive the output. On my system, this SBasic...

Code
Select All
var vPrinters as String
var vPrinterList as String

	// Run the OS command to list printers
	// Redirect the output to a string variable
	vPrinters = @RedirectProcess("cscript C:\WINDOWS\system32\prnmngr.vbs -l", "")

	// Replace end of lines with semicolons
	vPrinters = @Replace(vPrinters, @Chr(13), ";")
	vPrinters = @Replace(vPrinters, @Chr(10), "")

	// Parse out the lines with a printer name
	vPrinterList = @SearchStringArray(vPrinters, "Printer name..")

	// Get rid of the "Printer name" part leaving only the name itself
	vPrinterList = @Replace(vPrinterList, "Printer name ", "")

	// Use the resulting list
	WriteLn(vPrinterList) 



..produces this output

QuickBooks PDF Converter;PDF995;Microsoft Office Document Image Writer;LJ2100;Auto HP LaserJet 2100 PCL6 on FRIAR;Auto HP LaserJet 2100 on TRAINING5;Auto HP LaserJet 2100 on TRAINING3



For reference, the partial raw output from the command line tool looks like this...
C:\WINDOWS\system32>cscript prnmngr.vbs -l
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.


Server name
Printer name QuickBooks PDF Converter
Share name
Driver name Amyuni Document Converter 2.50
Port name LPT1:
Comment
Location
Print processor WinPrint
Data type RAW
Parameters
Attributes 66
Priority 1
Default priority 0
Status Unknown
Average pages per minute 0

Server name
Printer name PDF995
Share name
Driver name PDF995 Printer Driver
Port name PDF995PORT
Comment
Location
Print processor WinPrint
Data type RAW
Parameters
Attributes 4161
Priority 1
Default priority 0
Status Unknown
Average pages per minute 0

Server name
Printer name Microsoft Office Document Image Writer
Share name
Driver name Microsoft Office Document Image Writer Driver
Port name Microsoft Document Imaging Writer Port:
Comment
Location
Print processor ModiPrint
Data type RAW
Parameters
Attributes 64
Priority 1
Default priority 0
Status Unknown
Average pages per minute 0

Server name
Printer name LJ2100
Share name
Driver name HP LaserJet 2100
Port name \\PC3\LJ2100
Comment
Location
Print processor WinPrint
Data type RAW
Parameters
Attributes 68
Priority 1
Default priority 0
Status Unknown
Average pages per minute 0


You can look up this tool for additional options and switches.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Printer Dialog Box or Printer Strings from OS
Reply #2 - Feb 20th, 2009 at 10:44pm
Print Post Print Post  
Thanks Erika. It works great!  Smiley
  
Back to top
 
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Printer Dialog Box or Printer Strings from OS
Reply #3 - Mar 21st, 2009 at 12:00pm
Print Post Print Post  
Erika, the code you have given works great with Windows XP. Recently I intstalled Sesame 2.1 on Windows Vista 64 machine. Everything worked flawlessly, however code that you have so kindly given to get the printers list failed. I looked further to find out that prnmngr.vbs did not exist in C:\Windows\System32 subdirectory. But I found that file in C:\Windows\System32\Printing_Admin_Scripts\en-US\   subdirectory.

I copied the file to C:\Windows\System32. It still did not get the printer list. I pointed the file to be in C:\Windows\System32\Printing_Admin_Scripts\en-US\, still no luck with the printer list.

What am I doing wrong. I believe it should work with Vista 64 bit. Everything else works great.  Thanks for your help.
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Printer Dialog Box or Printer Strings from OS
Reply #4 - Mar 22nd, 2009 at 3:09am
Print Post Print Post  
if you run:

cscript prnmngr.vbs -l

from a command line, after changing directories to the directory where prnmngr.vbs resides, do you get any error messages, or do you get an output similar to the one Erika posted?
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Printer Dialog Box or Printer Strings from OS
Reply #5 - Mar 22nd, 2009 at 6:31pm
Print Post Print Post  
Thanks for giving proper direction. Come to find out that cscript.exe file is in C:\Windows\sysWOW64\  directory.  If I go to c:\windows\syswow64\ directory and place the following command the expected output is generated.

cscript c:\windows\system32\Printing_Admin_Scripts\en-US\prnmngr.vbs -l

My question is, can I copy and paste cscript.exe and prnmngr.vbs files in c:\windows\system32\ directory so as to  the original command to work?

Thanks for your help. Now I know this will work even in Windows Vista 64 bit system, but I am exploring it to work without changing anything in my code.

Bharat


  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Printer Dialog Box or Printer Strings from OS
Reply #6 - Mar 22nd, 2009 at 10:15pm
Print Post Print Post  
You probably shouldn't move or copy the files found in the operatinf system directories. Instead, change the SBasic code to have the full paths to both files where MS originally put them on your version of windows.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Printer Dialog Box or Printer Strings from OS
Reply #7 - Mar 27th, 2009 at 12:05am
Print Post Print Post  
Thanks Mark. Everything in Sesame 2.1 works well in Vista 64 bit system.
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Printer Dialog Box or Printer Strings from OS
Reply #8 - Mar 27th, 2009 at 12:50am
Print Post Print Post  
Bharat_Naik wrote on Mar 27th, 2009 at 12:05am:
Thanks Mark. Everything in Sesame 2.1 works well in Vista 64 bit system.


I've been looking into the issues surrounding building 64 bit native Sesame. The older 32 bit application files will have to be converted before use and the resulting 64 bit applications can't be back compatible. But, other than that. it would be nice to have the giant address space available.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Printer Dialog Box or Printer Strings from OS
Reply #9 - Mar 27th, 2009 at 4:41am
Print Post Print Post  
That would be real nice. We do upgrade the application files with major update and upgrade of the programs anyway (such as going from version 1.xx to 2.xx).  Looking forward to that leap into 64 bit application. What improvement would it have in terms of speed and other tangibles? Thanks.
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Printer Dialog Box or Printer Strings from OS
Reply #10 - Mar 27th, 2009 at 12:35pm
Print Post Print Post  
Bharat_Naik wrote on Mar 27th, 2009 at 4:41am:
What improvement would it have in terms of speed and other tangibles? Thanks.


For smaller installations, there would be no difference. But with the larger address space (more memory), larger installations would see an improvement, and there would be less reason to balance load between multiple machines.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged