CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2000
    Posts
    149

    Using DOS Copy command within a shell

    Hello,
    I am having a devil of a time with this problem.
    At my network here at work, if I start my DOS prompt and type the following:
    copy C:\labels\myfile.txt \\sean\hp

    HP is my printer on my computer and the file prints fine. So I want to add that functionality to a labelmaker that I wrote, but if I try to use the Shell like this:


    Shell "copy c:\labels\myfile.txt \\sean\hp"




    I have also tried :

    Shell "Command.com /c copy c:\labels\myfile.txt \\sean\hp"




    and this:

    Shell "c:\labels\copy myfile.txt \\sean\hp"




    I get the file not found error message, though the file is certainly there.

    Any way around this???

    Thanks,
    Sean


  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Using DOS Copy command within a shell

    Try this it works for me


    Public Const FILEPATH = "c:\temp\exc.txt" 'exception report
    Public Const NETWORKPRINT = "f:\public\nprint"
    Public msOutqueue As String ' - outqueue name
    Public msServer As String' server name


    Call PrintTextFile(FILEPATH) - procedure call

    Public Sub PrintTextFile(ByVal sTextFile As String)
    '==============================================================================
    'this sub shells to DOS and call nprint command to print the text file
    Dim r As Variant
    Dim sCommandString As String
    Dim sQ As String
    Dim sServerString As String


    'DOS command line -> nprint file.txt q=YourOutqueue s=ServerName nt nb ff

    sQ = msOutqueue 'defined in login form
    sServerString = msServer & " nt nb ff" 'msServer defined in login form
    sCommandString = NETWORKPRINT & " " & sTextFile & " q=" & sQ & " s=" & sServerString


    r = Shell("start.exe " & sCommandString, vbHide)
    End Sub






    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  3. #3
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Using DOS Copy command within a shell

    Also try this

    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _
    ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long

    Dim lngResult As Long
    lngResult = ShellExecute(Me.hwnd,"Print",strFile,0&,0&,vbMinimized)

    where strFile is the full path to your file





    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  4. #4
    Join Date
    Feb 2000
    Posts
    149

    Re: Using DOS Copy command within a shell

    Iouri,
    this works only if my file is a registered type, and when it does it opens the program that is registered to it before printing, that is not acceptable for this situation, thanks for the tip though.

    What really frustrates me is why a simple FileCopy doesnt work for a printer.
    I have tried:

    FileCopy "C:\Labels\Myfile.d00" , "\\sean\hp"



    And it errors out.


  5. #5
    Join Date
    Feb 2000
    Posts
    149

    Re: Using DOS Copy command within a shell

    Ok I finally got it, nothing worked until I searched old posts about the FileCopy method, and I found a post that you wrote about the FileSystemObject the CopyFile method!!! it works!!! I should have known, I have always had great success with FSO.
    Thanks


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured