xp_cmdshell

  • USE master

    EXEC xp_cmdshell "print c:\temp.txt " , NO_OUTPUT

    I am trying to execute above command and I could not print the text file.

    The printer has been set up on the same machine SQL server is running

    Can somebody help me out please

  • Remove the no_output parameter, rerun the xp and post again the error message you get.

  • USE master

    EXEC xp_cmdshell 'print /D:\\server-3\\hp4100 C:\temp.txt'

    OutPut

    1 Enable to initialize device \\server-3\\hp4100

    2 NULL

  • I am have the same problem, and I am trying to find de solution..

  • longingfriend (4/28/2003)


    USE master

    EXEC xp_cmdshell 'print /D:\\server-3\\hp4100 C:\temp.txt'

    OutPut

    1 Enable to initialize device \\server-3\\hp4100

    2 NULL

    Are you sure the output isn't ...

    1 [font="Arial Black"]U[/font]nable to initialize device \\server-3\\hp4100

    ???

    Also, have you tried running that same command from an actual command prompt window? If it doesn't work there, it's not going to work from SQL Server.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

  • Hi people,

    My problem is exact the same.

    I have one cmd thats use PRINT command, when I execute this cmd it´s work.

    But when a try use xp_cmdshell to execute the error occours.

    Unable to initialize device .....

    I try to map the shared printer as a LPT port but its doesn't work to.

    When a try to use the command COPY File.xt \\Server\Printer_share, the error change.

    Access denied...

    It´s is related to the account used by SQL Server to run de service?

    How to change it´s without security mistakes?

    Tank´s..

  • This is likely a security/config error for the service account of SQL Server, or the proxy for xp_cmdshell.

    First get an account that makes this work. Not your account, but create a domain account and slowly assign rights and configure it to work from the command prompt, when logged in as that account.

    Then use that account as the xp_cmdshell proxy.

  • login using windows authentiation. and then try it

  • Hello,

    Using an other domain account on SQL Server service a can print as I want.

    But now I am thinking about security consequences, I should give to this account only print rights to make what I need, but what are the others rights that SQL need to work correctly? Should this account be one local administrator?

    Thank´s.

  • Which account? If you set a proxy for xp_cmdshell, just give it the rights needed.

    If you change a service account, use the Configuration Manager. It will assign the correct rights for SQL Server.

  • I try to use this proxy for cmdshel and doesn't work.

    Them I change the SqlServer service account, with this change I can print using the xp_cmdshell.

    My question now is, wich are the rights that a should give to this user (a domain user)?

    Tank´s

  • If you assign the account to SQL Server using the Configuration Manager, it will determine the rights for SQL Server to run.

    If you mean that the account you used for the proxy does not work, it needs the rights to accomplish the task. so rights to the printer.

Viewing 12 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic. Login to reply