We help IT Professionals succeed at work.

VB/NET changing default printer during application

I have written a web form that needs to change the default printer during the run based on a file that the machine uses,
so when a user fills out the form and hit the print button, the app checks the file for the machine name and then checks the file for the appropriate printers,
it then needs to change the default printer to the printer name on the file.using the printfile application which is set to use the default printer.
unless anyone is familiar with printfile to change the printername in that.
I tried the setdefaultprinter() Method but it isn't chnaging the default printer.
i
Thanks in advance
Comment
Watch Question

Author

Commented:
Thanks
Éric MoreauSenior .Net Consultant
BRONZE EXPERT
Top Expert 2016

Commented:
do you want to change the default printer of the server where the web app runs or the on the client ?

Author

Commented:
the default printer is already installed on the client, but it is a network printer
so for example the current printer is HP 3500
but clicking the print button the app has already determined the new printer, but before it prints it
needs to chnage the defualt to that printer which would be something like
\\{servername}\{printername
this is what i currently have
    <DllImport("Winspool.drv")> _
Private Shared Function SetDefaultPrinter(ByVal printerName As String) As Boolean

    End Function


and  then in on click event
 SetDefaultPrinter(printername)


Thanks in advance
Éric MoreauSenior .Net Consultant
BRONZE EXPERT
Top Expert 2016

Commented:
you want to change the client default printer?

if your SetDefaultPrinter is in your .aspx.vb file, the code will run on the server and won't affect the client.
Éric MoreauSenior .Net Consultant
BRONZE EXPERT
Top Expert 2016

Commented:
if you want the client, I doubt you can do it directly but check http://www.meadroid.com/scriptx/index.asp

Author

Commented:
It is a windows form which will actually run on the machine that it will need to change the defauklt.
so in essence I guess that will be fine,
any way to do it.
I thought I had it working but it seemed funny.

Thanks in advance
Senior .Net Consultant
BRONZE EXPERT
Top Expert 2016
Commented:

Explore More ContentExplore courses, solutions, and other research materials related to this topic.