Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

set printer to \\machinename\printername - HELP!

Status
Not open for further replies.

SqueakinSweep

Programmer
Jun 20, 2002
945
0
0
GB
I have a FPD 2.6 application that sits on a W2K Server, and is accessed by many clients W95,W98 and now W2K. I control printing over the network by redirecting print via the LPT3 port as follows.
Code:
set printer to \\machinename\printername = lpt3
All works well and has done for years, until the introduction of W2K clients. Whereas I can happily type in a net use command to map the correct printer, Fox generates an INVALID PRINTER REDIRECTION, whenever I run the above code.

Does anyone know of any workarounds to this problem, or otherwise as to a possible alternative solution. I dont want to fix the printers to individual NET USE ports, as there are more than 3 printers that I may need to print to

Regards





Sweep
...if it works dont mess with it
 
If you would do a Keyword Search for other similar postings you will find many postings on this topic.

You might want to begin by looking at: thread182-683068 from just a few days ago.

In general, your problem is attempting to run a DOS product which directly accesses hardware printer ports in a non-DOS supporting (or more accurately minimally supporting) operating system. Win 2000 and Win XP will not let you directly access hardware ports (e.g. LPT1, 2, 3, COM1, 2).

Re-writing your application in a more current version of Foxpro would resolve your problem and it would be the best solution, but I understand how that might not be feasible for everyone.

Hopefully you will find a solution among the numerous similar postings.

Good Luck,


JRB-Bldr
VisionQuest Consulting
Business Analyst & CIO Consulting Services
CIOServices@yahoo.com
 
Rewriting the application isnt an option right now. I may be able to work around the problem, but its not an ideal solution

I have seen a lot of reference to TAMEDOS. Does anyone who has TAMEDOS know if this will resolve my original problem.

How has anyone else worked around the printer redirection problem?





Sweep
...if it works dont mess with it
 
No, TameDOS just addresses a problem where DOS apps continually poll the keyboard and cause 100% CPU utilization.

I think the only 100% foolproof solution is to use NET USE commands in Windows and then just print to the relevant LPT in your app, i.e. SET PRINTER TO LPT2.

You have up to 9 which should handle most requirements.

***************************************
Need help running those old FoxPro apps on modern systems?
 
Thanks Mickey

Never realised I had up to 9! I may look at utilising net use within my app. I have a printers table which contains the network names. eg \\user2\prnlabel, and I use a piece of Fox code to swap the printer. Ive always used LPT3, so I guess I could do the following in my app.

Code:
if Win2K
   run net use lpt3: /d >null
   run net use lpt3: \\user2\prnlabel >null
   set printer to lpt3:
else
   set printer to \\user2\prnlabel = lpt3
endif

Any reason why the above wouldnt work?


Sweep
...if it works dont mess with it
 
Ahh...hence the redirection to >null, which avoids the nasty popup you describe.

I'll give it a go anyway, if not I'll resort to fixing the mappings before I enter the application.



Sweep
...if it works dont mess with it
 
OnePunchMickey was right to suggest NET USE. But how would you know if the printer connection failed if you dump the screen message? I like to save it to a file so I can determine the connection status, as you can see in the program below. One note concerning rights, in NT/2K/XP you must be logged on with administrator rights before you can write to the root drive, so that's why I have the file written to \Windows\Temp which exists in all Windows versions.

Here is some code I've used in dBase 5 for DOS. It may not take much tweaking to get it working smoothly in FoxPro.

Code:
PROCEDURE pr_link
PARAMETERS p_cpu, p_prname
*  Note: if p_cpu="DELETE" or undefined/empty then release LPT2 as default
*  p_cpu contains computer name
*  p_prname contains printer share name, defaults to "printer"
PRIVATE c_cmd, l_fail, c_dest, n_hand, c_data
l_fail=.F.
* Windows 2000/XP require deletion of prior NET USE connection
c_dest="C:\WINDOWS\TEMP\_NUL.TMP"
IF FILE(c_dest)
   ERASE (c_dest)
ENDIF
c_cmd = "NET USE LPT2 /DELETE > "+c_dest
! &c_cmd
* Me fail message: "Error 3: ..."
* XP fail message: "The network connection could not be found. ..."
IF TYPE(&quot;p_cpu&quot;)=&quot;C&quot; .AND. p_cpu<>&quot;&quot; .AND. UPPER(p_cpu)<>&quot;DELETE&quot;
   IF FILE(c_dest)
      ERASE (c_dest)
   ENDIF
   c_cmd=&quot;NET USE LPT2 \\CPU-&quot;+p_cpu+&quot;\&quot;;
        +IIF(TYPE(&quot;p_prname&quot;)=&quot;C&quot;,p_prname,&quot;printer&quot;);
        +&quot; > &quot;+c_dest
   ! &c_cmd
   IF FILE(c_dest)
      n_hand=FOPEN(c_dest)
      IF n_hand>0
         c_data=FREAD(n_hand,254)  && dBase string limit
         n_hand=FCLOSE(n_hand)
         IF &quot;Error&quot; $ c_data .OR. ;
             .NOT. &quot;completed successfully.&quot; $ c_data
            c_data=STRTRAN(c_data,CHR(13))
            c_data=STRTRAN(c_data,CHR(10))
            IF LEN(c_data)>0
               l_fail=.T.
               WAIT c_data  && display failure message
            ENDIF
         ENDIF
      ENDIF
      ERASE (c_dest)
   ENDIF
ENDIF
pr_done= .NOT. l_fail
pr_fail=l_fail
* pr_done/pr_fail are external variables holding results
* but if this procedure is converted to a function
* then a value could be returned on the RETURN line
RETURN

dbMark
 
You might try
?sys(1037)
set print on
... print report
set print off
set print to
 
Just one note about my program above. It expects SET EXACT ON.

dbMark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top