none
DocumentProperties function fails from Terminal Server RRS feed

  • Question

  • I have the following code in my print macro for Word to get and change the properties of the printer.

          pd.DesiredAccess = PRINTER_ALL_ACCESS
          nRet = OpenPrinter(sPrinterName, hPrinter, pd)
          If (nRet = 0) Or (hPrinter = 0) Then
             If Err.LastDllError = 5 Then
                MsgBox "Access denied -- See the article for more info."
             Else
                MsgBox "Cannot open the printer specified " & _
                  "(make sure the printer name is correct)."
             End If
             Exit Function
          End If
       
          nRet = DocumentProperties(0, hPrinter, sPrinterName, 0, 0, 0)
          If (nRet < 0) Then
             MsgBox "Cannot get the size of the DEVMODE structure."
             GoTo cleanup
          End If

     

    The code works on all computers in our office, but when logged into our Terminal Server (2008 R2) it fails at the nRet = DocumentProperties() step.  It returns a value of -1.  On the local computer it doesn't fail.

     

    I'm logged in with the same username and printing to the same printer.

     

    Can anyone tell me why the DocumentProperties() function will fail from the Terminal Server?

     

     

     

    Wednesday, September 28, 2011 8:11 AM

All replies

  • Hi Faniedt,

    Thanks for your post.

    I could understand the issue you described. But I could not track the reason at once. Could you please set breakpoint to debug step by step to check from which code line the variables' value are not correct? Which word edition do you use? When logged into our Terminal Server (2008 R2), other functions except DocumentProperties() work fine? Could you please provide more detail information?

    Have a nice day.

    Best regards

     


    Liliane Teng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, September 30, 2011 9:11 AM
  • It is Word 2007.  It seems that other functions work.  I will check the variable values.
    Friday, September 30, 2011 9:28 AM
  • On Terminal Server the values of the variables in the DocumentProperties() functions are:
    hPrinter = 168100020

    sPrinterName = \\zatshprt01\PRTDUP

    nRet = -1


    On Local computer the values were:
    hPrinter = 122125996

    sPrinterName = \\zatshprt01\PRTDUP

    nRet = 7792

    Friday, September 30, 2011 10:11 AM