Information Technology Reference
In-Depth Information
Using the Registry
You can share a printer by modifying the following Registry value:
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\
<PrinterName>
\]
"ShareName"="<
YourShareName
>"
Replace
<
PrinterName
>
with the name of your printer, and replace
<
YourShareName
>
with
the desired share name.
Here is an example:
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\
HP LaserJet 1300\]
"ShareName"="Accounting Printer"
When you've finished, restart the Print Spooler service (see Recipe 8-8).
Using VBScript
You can share a network printer and publish it in Active Directory by executing the
prncnfg.vbs
script, located in your
%systemroot%\system32
directory. Use the following syntax to create
the share:
> cscript prncnfg.vbs -t -p
<PrinterName>
[-s
<RemoteComputer>
]
[-u
<UserName>
-w
<Password>
] -h
<ShareName>
{+ | - }shared {+ | -}published
Here is a description of the parameters:
-t
: Required parameter that indicates that you are going to configure the printer.
-p
PrinterName
: Required parameter that specifies the name of the printer that you are
about to share. Enclose the printer name in quotation marks.
-s
RemoteComputer
: Optional parameter that specifies the name of the host if the share is
on a remote system. Enclose the hostname in quotation marks.
-u
UserName
-w
Password
: Optional parameters that provide the credentials needed to take
the action on the desired host. Enclose both the username and the password in quotation
marks.
-h
ShareName
: Required parameter that specifies the share name. Enclose the share name
in quotation marks.
+ | - shared
: Parameter that specifies whether you plan to create or delete the share. The
plus symbol (
+
) indicates that you will create the share. The parameter is optional in the
overall syntax of
prncnfg.vbs
, but we will consider it required in this case, since part of the
goal of this recipe is to share the printer.
+ | - published
: Parameter that specifies whether the printer will be published in Active
Directory. The plus symbol (
+
) indicates that you will publish the printer. The parameter is
optional in the overall syntax of
prncnfg.vbs
, but we will consider it required in this case,
since part of the goal of this recipe is to publish the printer.
For example, to share and publish a printer named HP LaserJet 1300 PCL 5e hosted on
PrintServer2 using the share name HR Printer and using the Administrator credentials, run the
following command: