Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sharing Printer from command line..

Status
Not open for further replies.

youngbm1

MIS
Dec 10, 2002
2
US
I have a DOS application running in XP, that will be deployed to a couple hundred users. The problem is printing from the application, in the field all printing will be IP based. I need to find a way to automate sharing the default printer, so the user doesn't have to, and capturing LPT1 using NET USE. I have a script that will capture LPT1 but I need a way to share the printer prior to capturing the port.
 
I think you may owe me a cold beer for this tip.

Under XP if the user is not an Adminstrator they will be blocked from assinging LPT1 with NET USE if they have a physical parallel port on their workstation.

Reference:
You need to modify any WHS script you are using, or any batch file, under XP to disable this device.

I provide a lengthy explanation in another thread on this site about how to use the devcon.exe utility from the SDK toolkit to do this. thread779-510555 near the bottom of the thread about how to use Devcon in a login script. You could just as easily apply it to any script, assuming you place devcon.exe in a directory that is a member of their PATH environmental variable.

Just remember these important "gotchas"
. Use devcon to disable under XP the local computer LPT1 device;
. You can then NET USE, or this trick. The /y parameter assigns under XP the default parameter for the printer:

rundll32 printui.dll,PrintUIEntry /in /n \\share_server\share_printername

# set as default printer, an optional choice:

rundll32 printui.dll,PrintUIEntry /in /n \\share_server\shareprintername /y

I think you owe me a beer.
 
bcastner,

Thanks for the reply, I'm sure the non-Admin issue would have bitten me in the @ss eventually, so your right I probably do owe you a beer.

I forgot to mention earlier they will not be using a print server. When the new workstations are deployed a local TCP/IP printer port will be established when the printer is added so the port will look like IP_99.99.99.99, hence the printer cannot point to the IP port and LPT1 at the same time, it has to be shared first and then the share used to capture LPT1.

That being said, I still am not sure on how to automate sharing the Default printer. I have found a way to determine the Default printer via a Registry look-up but I don't know how to share the printer once found. Ideally I would like this script to run as a logon script, it will release LPT1, determine the default printer, determine if it's shared and if not, share it as a standard name, then capture the LPT1 port using
net use lpt1 \\%computername%\standard_name

I saw that rundll32 printui.dll,PrintUIEntry has the ability to share a printer but only when using /if which is installing a printer from an .inf file.
 
You should not surprise XP by requesting to share a printer, or NET USE a printer without an acceptable driver installed.

If you do this from a CMD session rundll32 printui.dll,PrintUIEntry /? you will see the complete syntax for the command. I am fairly good about the arcane of XP, but I know there is a switch for forcing a printer driver install if you fully path the location of the driver. These seems to me something that should be done locally, but one of the arcane aspects of this facility is the ability to install remotely if the driver is not available.

A print server is not needed. What is needed is a frank and practical appraissal of how printers are in the main used. If you have a lot of local printer assignments for printing by the local machine, good. Do you have occasional use of remotely connected printers, okay. But it escapes me why you need per-user a reset of all printer definitions.

Bet that as it may:

. You have the link to command line remove local printers through devcon.exe
. You know how to net use lptx \\, etc.
. You know how to identify to the workstation that the printer is the default;
. You should know how if the printer driver is not available how to load it remotely;
. And neither NET USE nor the direct rundlll32 care if you use an IP assignment or a Nebios name for a statment like NET USE LPT12: \\192.168.24.112\laserjet4si

If your WINS, and/or DNS service locally is sound, the assignment by IP or NETBIOS name should succeed.

If it is problematic, use the rundll32 first to assign the printer to a local port, then use either runndll32 or NET SHARE to convert the assignment to a NETBIOS name. Windows is happy either way.

And now you owe me, I think, two beers.
 
I just ran into this 'can't map lpt1 if you are a non-admin' problem but the fixes mentioned in this and a linked thread can't help me. The reason: the users need to be able to change from a network printer and a local printer connected directly to lpt1. For win98/2K, I created a simple batch file that maps the network printer to lpt1 and another one to delete the mapping.

Most of the time, the users print to their local printers. WHen they need the network printer (a wide-format dot matrix for forms), they simply click the shortcut to the first batch file and print. Then they click the other one to print back to their local printers. The program in question is a legacy dos app that cannot recognize anything besides lpt1.

So short of giving them all admin privileges, is there a fix?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top