Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: default printer
Syntax: pAddPrinter(server-name, printer-name, port-name, driver-name, print-processor) Parameters: (s) server-name In Windows 95, this is not used, and should be set to "". You can only add printers for the local machine. In Windows NT, this specifies the machine on which to create the printer. The caller must have admistrative access to the server. You can specify "" for the local machine. (s) printer-name the name you want for the newly-added printer. (s) port-name printer port. (ie., LPT1) (s) driver-name must be the name of an already-installed driver. This should be the driver's display name (eg, as shown in the pull-down listbox for "Print using the following driver" under a printer's properties), not the file name. (s) print-processor will almost always be "WinPrint". Returns: (i) 1 on success, or a negative error code on failure. Note that this function may take a minute or so to complete. Example: AddExtender("WWPRT44I.DLL") pAddPrinter("", "My new printer", "LPT1:", "HP LaserJet 4", "WinPrint")
Run commandline:
ShellExecute('rundll32', 'printui.dll,PrintUIEntry /in /n \\server\printername', '', @NORMAL, '') ;adds the printer ShellExecute('rundll32', 'rundll32 printui.dll,PrintUIEntry /in /n \\server\printername /y', '', @NORMAL, '') ; makes it defaultThis is to add the printer for a particular user. It may be that the user is not authorized to add the printer and you may get an error: You do not have sufficient access to your computer to connect to the selected printer.
In that case, you'll have to run the script as an aministrator on the computer and add the printer to the system globally, not just the one user:
ShellExecute('rundll32', 'printui.dll,PrintUIEntry /ga /c\\computername /n\\server\printername', '', @NORMAL, '') ; add the printer to the system globallyIf you are adding the above to a login script replace computername with the environments COMPUTERNAME. This way it will automatically insert the name of the current computer.
computername = Environment( "COMPUTERNAME" ) ShellExecute('rundll32', 'printui.dll,PrintUIEntry /ga /c\\':computername:' /n\\server\printername', '', @NORMAL, '') ; add the printer to the system globallyTo delete the printer globally, run the following:
computername = Environment( "COMPUTERNAME" ) ShellExecute('rundll32', 'printui.dll,PrintUIEntry /gd /c\\':computername:' /n\\server\printername', '', @NORMAL, '') ; Delete the printer from the system globallyUsing COM:
;Add printers strUNCPrinter = "\\servername\printername" strPort = "LPT2" strPort = "" strUNCPrinter = "" objNetwork = ObjectCreate("WScript.Network") objNetwork.AddWindowsPrinterConnection( strUNCPrinter ) objNetwork.AddPrinterConnection( strPort,strUNCPrinter ) objPrinter.SetDefaultPrinter( strUNCPrinter ) objNetwork = 0
Article ID: W13681
Filename: Add a Printer to NT-95 and Make it the Default Printer.txt
File Created: 2012:10:05:09:17:46
Last Updated: 2012:10:05:09:17:46