Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Microsoft: FoxPro FAQ


How to change default printer by Mike Gagnon
Posted: 13 Sep 02 (Edited 8 Nov 02)

There are a few ways to do this, one is a two lines of code (assuming that Windows Scripting v5.6 is installed):
oNet = CREATEOBJECT("WScript.Network")
oNet.SetDefaultPrinter("\\slp_nt_termserv\Panasonic Printer")

This also works on local printers.
oNet.SetDefaultPrinter("Epson FX-80+")
Or using an API call like this:

 Printers = ""
   Number = 0
   Defa_print = ""
   DO GETPRINT WITH Printers, Number, Defa_print
   *Printers   - is an array with all the printers installed.
   *Number     - is the number of printers in the WIN.INI file.
   *Defa_print - is the default printer in the WIN.INI file.

   DO PUTPRINT WITH Printers, Number, NEW_DEFA
   *Printers   - is the return array from the GETPRINT.
   *Number     - is the return number of printers from GETPRINT.
   *NEW_DEFA   - is the new default string that will be put directly into
   *             the WIN.INI file (e.g., "HP LaserJet III,HPPCL5MS,LPT1;")
   *             This should only be done if you know exactly what should
   *             be in the Default printer string.

   PROCEDURE getprint
   #DEFINE buflen 2048
   PRIVATE m.in_talk, m.dcount, m.retbuf, m.bytes, m.thisdevice

      WAIT WINDOW "This procedure requires 3 parameters"

      SET LIBRARY TO (SYS(2004)+"foxtools.fll") ADDITIVE
      WAIT WINDOW "GETPRINT requires the FoxTools library."

   IF SET("TALK") = "ON"
      m.in_talk = "ON"
      m.in_talk = "OFF"
   m.retbuf = REPLICATE(CHR(0),buflen)
   m.bytes = getprostrg("devices",0,CHR(0),@m.retbuf,buflen)
   m.dcount = 0
   m.retbuf = LEFT(m.retbuf,m.bytes)
   DO WHILE CHR(0) $ m.retbuf
      m.thisdevice = LEFT(m.retbuf,AT(CHR(0),m.retbuf)-1)
      IF LEFT(m.thisdevice,1) <> CHR(0)
         m.dcount = m.dcount + 1
         DIMENSION device[m.dcount,3]
         device[m.dcount,1] = m.thisdevice
      m.retbuf = SUBSTR(m.retbuf,AT(CHR(0),m.retbuf)+1)
   FOR m.j = 1 TO m.dcount
      retbuf = REPLICATE(CHR(0),256)
      m.bytes = ;
      m.retbuf = LEFT(m.retbuf,m.bytes)
      device[m.j,2] = m.retbuf

      retbuf = REPLICATE(CHR(0),256)
      m.bytes = ;
      m.retbuf = LEFT(m.retbuf,m.bytes)
      device[m.j,3] = m.retbuf
   m.number = m.dcount
   retbuf = REPLICATE(CHR(0),256)
   m.bytes = getprostrg("windows","device",CHR(0),@m.retbuf,256)
   m.retbuf = LEFT(m.retbuf,m.bytes)
   m.dfltprnt = m.retbuf

   SET TALK &in_talk
   PROCEDURE listprint
   #DEFINE buflen 2048
   PRIVATE m.in_talk,m.i
      SET LIBRARY TO (SYS(2004)+"foxtools.fll") ADDITIVE
      WAIT WINDOW "LISTPRINT requires the FoxTools library."
   IF SET("TALK") = "ON"
      m.in_talk = "ON"
      m.in_talk = "OFF"

   NUMBER = 0
   dflt = ""

   DO getprint WITH DEVICE, NUMBER, dflt
   ? ALLTRIM(STR(m.number,3))+" installed printer devices in win.ini:"
   FOR m.i = 1 TO NUMBER
      ? "  "+device[m.i,1]+"="+device[m.i,3]
   ? "Default printer is "+dflt
   SET TALK &in_talk
   PROCEDURE putprint
   PARAMETER DEVICE, NUMBER, dflt, portnum
      SET LIBRARY TO (SYS(2004)+"foxtools.fll") ADDITIVE
      WAIT WINDOW "PUTPRINT requires the FoxTools library."

   IF TYPE("dflt") = "N"
      IF PARAMETERS() < 4
         portnum = 1
      m.strg = device[m.dflt,1]+","+getport(device[m.dflt,2],portnum)
      m.strg = m.dflt
   FOR m.i = 1 TO NUMBER
   FUNCTION putprostrg
   PARAMETER SECTION, entry, string
   fn = regfn("WRITEPROFILESTRING","CCC","I")
   RETURN callfn(fn,SECTION,entry,string)
   FUNCTION getprostrg
   PARAMETER SECTION, entry, dflt, buffer, blen
   fn = regfn("GETPROFILESTRING","CCC@CI","I")
   RETURN callfn(fn,SECTION,entry,dflt,@buffer,blen)
   FUNCTION getport
   PARAMETER m.pstrg, m.pnum
   m.retstrg = SUBSTR(m.pstrg,1,AT(',',m.pstrg))
   IF OCCURS(',',m.pstrg) >= m.pnum
      m.portstrg = SUBSTR(m.pstrg,AT(',',m.pstrg,m.pnum)+1)
      m.portstrg = SUBSTR(m.pstrg,AT(',',m.pstrg,1)+1)

   IF AT(',',m.portstrg) > 0
      m.portstrg = LEFT(m.portstrg,AT(',',m.portstrg)-1)

   RETURN m.retstrg + m.portstrg

Mike Gagnon

Back to Microsoft: FoxPro FAQ Index
Back to Microsoft: FoxPro Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close