Jump to content
Macro Express Forums

Selecting A Printer


jmb4370

Recommended Posts

How can I build a selection list of installed printers, so that when the macro runs, the user can select a printer other than the default, run the macro, and then return back to the default printer? I know I could use the mouse and keyboard to get to the Printers and Faxes folder, but I think there must be an easier way, even reading a registry key.

 

Thanks everyone!

Michael

Link to comment
Share on other sites

How about if you create a shortcut link to the Printers and Faxes within the Control Panel and then use the Launch Program command to fire it off. This would at least get you a window containing all of the printer names. You could also do a search for one of the printer names in your Registry to find out which hives contain the printer names.

Link to comment
Share on other sites

I can read the registry value of the default printer in the registry key:

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device

The list of installed printer doesn't seem to appear anywhere as data values, but as the keys themselves in:

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices or HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts

It seems that the best I can do is to export the Devices or PrinterPorts branch to a text file and then parse that file to retrieve the shortened names to be used in the Default Printer command (through a multiple choice dynamically built menu)

 

Any other suggestions would be appreciated!

Thanks,

Michael

Link to comment
Share on other sites

Another solution is to use the msinfo32.exe program.

c:\Program Files\Common Files\Microsoft Shared\MSInfo\msinfo32.exe /report c:\Temp\printers.txt /categories +componentsprinting

Here is a macro that will create a file of the printer names using the above program (mxe attached):

// Program file
Variable Set String %T1% "msinfo32.exe"
Variable Set String %T2% "c:\Program Files\Common Files\Microsoft Shared\MSInfo"

// Output file
Variable Set String %T3% "printers.txt"
Variable Set String %T4% "c:\temp"

// Delete output file if it exists
If File Exists "%T3%"
 Delete File or Files: "%T3%"
End If

// Launch program
Program Launch: "%T1%"
Wait for File Exist: "%T3%"

// Strip the double-byte(?) characters
Variable Set String %T5% from File: "%T3%"
Variable Set Integer %N1% from Length of Variable %T5%
Repeat with Variable using %N1%
 Variable Modify String: Copy Part of %T5% to %T6%
 Variable Set %N6% to ASCII Value of %T6%
 If Variable %N6% > 0
   AND
 If Variable %N6% < 127
   Variable Modify String: Append %T6% to %T10%
 End If
Repeat End

// We only want the printer section
Variable Set Integer %N1% from Position of Text in Variable %T10%
Variable Modify Integer: %N1% = %N1% + 9
Variable Modify String: Delete Part of %T10%
Variable Modify String: Save %T10% to Text File
Macro Return

Note that, for whatever reason, the output file is created as double-byte characters ... or some such thing. So there is a loop that removes any characters from the string that are not between ASCII 01 and ASCII 126 and then re-saves the file.

 

The file that is created will still need to be processed. Hint: each "field" in each of the remaining lines is separated by a <Tab> character. You will only want the first field. Also, you will want to ignore the "header" line.

SystemPrinters.zip

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...