Microsoft KB Archive/244185

= PRB: Cannot Use FileCopy to Copy a File to a Printer =

Article ID: 244185

Article Last Modified on 7/16/2004

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 4.0 Enterprise Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 4.0 Standard Edition

-



This article was previously published under Q244185



SYMPTOMS
The following code generates an "Invalid Parameter" error message on Microsoft Windows NT or Windows 2000 but works fine on Windows 95 or Windows 98: FileCopy "c:\config.sys", "\\PrintServer\Printer" However, the following code works fine on Windows NT or Windows 2000 but generates an "Invalid Parameter" error message on Windows 95 or Windows 98: FileCopy "c:\config.sys", "lpt1"



CAUSE
Beginning with Visual Basic 4.0, 32-bit, the FileCopy method no longer supports copying files to a port. Windows NT changes Command.com, which FileCopy uses. Thus, FileCopy behaves differently on Windows NT and Windows 2000 than on Windows 95 and Windows 98.



RESOLUTION
To resolve this problem, use one of the following methods:   To copy a file to a port, use the following code: 'On Windows 95/98, the copy command in Command.com can copy to a printer. 'On Windows NT/2000, it cannot. However, the copy command in Cmd.exe can. 'If you call Cmd.exe on Windows 95/98, you receive error 53 - File not found. On Error Resume Next Shell "cmd /c copy c:\config.sys \\PrintServer\Printer" If Err.Number = 53 Then Shell "command.com /c copy c:\config.sys \\PrintServer\Printer" Else Err.Raise Err.Number End If On Error GoTo 0 'This also runs Err.Clear. On Windows NT, shelling Command.com or 'shelling a batch file fails with "Invalid Parameter." 'It only works when you specify CMD in the shell statement.  Use the Win32 application programming interfaces (APIs) to send information directly to the printer instead of copying files to the port. For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

154078 HOWTO: Send Raw Data to a Printer Using the Win32 API from Visual Basic

NOTE: Because this method uses APIs that bypass the printer driver, the program must prepare printer language code and send it to the printer for anything other than plain ASCII text, just as a printer driver would. As a result, you must write the program so that it sends PCL or PostScript code to the printer.

