Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Batch file - add network printers via printui.dll, PrintUIEntry

5,200 views
Skip to first unread message

aroy

unread,
Jul 28, 2008, 6:51:46 PM7/28/08
to
Greetings all,

I have a client who chooses to deploy printers via their login script.
For each of the ~30 printers I have a batch file containing:

:: Setting the default printer
rundll32 printui.dll,PrintUIEntry /in /n "\\server_name
\printer_name01"
rundll32 printui.dll,PrintUIEntry /y /n "\\server_name\priner_name01"

:: Setting the alternate printer
rundll32 printui.dll,PrintUIEntry /in /n "\\server_name
\printer_name02"

Users access is to these files is controlled by using ifmember.exe. If
user is a member of printer_group03 then run this batch file else move
on to next.

This works fine.

BUT, each time they login this scrip it run. How can I first check to
see if a specific printer is installed before adding it?

Essentially what I want to do is:

If exist(on local computer, NOT server) \\server_name\printer_name01
goto exit
if NOT exist \\server_name\printer_name01 add it

Is that at all possible??

thanks.

Pegasus (MVP)

unread,
Jul 29, 2008, 1:37:33 AM7/29/08
to

"aroy" <aaro...@gmail.com> wrote in message
news:5518af76-da58-4afe...@k36g2000pri.googlegroups.com...

Have a look at this help command: rundll32 printui.dll,PrintUIEntry /?


aroy

unread,
Jul 29, 2008, 1:20:32 PM7/29/08
to
On Jul 28, 10:37 pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
> "aroy" <aaronm...@gmail.com> wrote in message

Thanks, best I can find in there is a /q. That hides the little dialog
box that pops up when the printer is added. That gets the job
done...sort of. The users are not bothered by the dialog box but, the
printers are still being installed each time they login regardless of
whether or not they are already installed.

I would still like to be able to check if the printer is installed on
the local machine first.

thanks,

Pegasus (MVP)

unread,
Jul 29, 2008, 2:46:59 PM7/29/08
to

"aroy" <aaro...@gmail.com> wrote in message
news:60a801cf-bc6e-43d3...@b2g2000prf.googlegroups.com...

thanks,
===========
You could use the script below but your users might not
appreciate the delay it introduces into the logon process.
Invoking it remotely and creating a local tell-tale file would
get around the delay.
Set objWMI = GetObject("winmgmts:\\.\root\CIMV2")
Set colPrn = objWMI.ExecQuery("SELECT * FROM Win32_Printer")

For Each objItem In colPrn
WScript.Echo "Printer name: " & objItem.name & VbCrLf & _
"====================================" & VbCrLf & _
"Port Name: " & objItem.PortName & VbCrLf & _
"Printer State: " & objItem.PrinterState & VbCrLf & _
"Printer Status: " & objItem.PrinterStatus & VbCrLf & _
"PrintJobDataType: " & objItem.PrintJobDataType & VbCrLf & _
"Print Processor: " & objItem.PrintProcessor & VbCrLf & _
"Spool Enabled: " & objItem.SpoolEnabled & VbCrLf & _
"Separator File: " & objItem.SeparatorFile & VbCrLf & _
"Status: " & objItem.Status & VbCrLf & _
"StatusInfo: " & objItem.StatusInfo & VbCrLf & _
"ShareName: " & objItem.ShareName & VbCrLf & _
"Horizontal Res: " & objItem.HorizontalResolution & VbCrLf & _
"Vertical Res: " & objItem.VerticalResolution
WScript.Echo "Work Offline: " & objItem.WorkOffline
Next


JFord

unread,
Jul 30, 2008, 9:31:01 AM7/30/08
to
A bit faster than WMI is the REG command...

:\>REG QUERY "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Devices" |
FIND /I "Printer Name"

based on %errorlevel% you can end or add

-J

Pegasus (MVP)

unread,
Jul 30, 2008, 10:24:34 AM7/30/08
to

"JFord" <JF...@discussions.microsoft.com> wrote in message
news:7B2FE55F-B7CD-47C4...@microsoft.com...

>A bit faster than WMI is the REG command...
>
> :\>REG QUERY "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Devices" |
> FIND /I "Printer Name"

The reg.exe command is not a bit faster than WMI, it
is always a lot faster!


J Ford

unread,
Jul 30, 2008, 1:37:01 PM7/30/08
to
True! A definite understatement on my part...

aroy

unread,
Jul 31, 2008, 10:23:47 AM7/31/08
to

Excellent thanks all...I am going to try JFords idea today when I get
back to the office.

Douglas Cowie

unread,
Oct 22, 2010, 11:16:13 PM10/22/10
to
Try this out:

@reg query hklm\system\currentcontrolset\control\print\printers
/f "HP Photosmart C4401 series" /z | find " 0 match" > nul && (do your printui.exe stuff, printer was not found)

> On Tuesday, July 29, 2008 1:19 AM aroy wrote:

> Greetings all,
>
> I have a client who chooses to deploy printers via their login script.
> For each of the ~30 printers I have a batch file containing:
>

> rundll32 printui.dll,PrintUIEntry /in /n "\\server_name
> \printer_name01"
> rundll32 printui.dll,PrintUIEntry /y /n "\\server_name\priner_name01"
>

> rundll32 printui.dll,PrintUIEntry /in /n "\\server_name
> \printer_name02"
>
> Users access is to these files is controlled by using ifmember.exe. If
> user is a member of printer_group03 then run this batch file else move
> on to next.
>
> This works fine.
>
> BUT, each time they login this scrip it run. How can I first check to
> see if a specific printer is installed before adding it?
>
> Essentially what I want to do is:
>
> If exist(on local computer, NOT server) \\server_name\printer_name01
> goto exit
> if NOT exist \\server_name\printer_name01 add it
>
> Is that at all possible??
>
> thanks.


>> On Tuesday, July 29, 2008 1:37 AM Pegasus \(MVP\) wrote:

>> Have a look at this help command: rundll32 printui.dll,PrintUIEntry /?


>>>> On Wednesday, July 30, 2008 9:31 AM JFor wrote:

>>>> A bit faster than WMI is the REG command...
>>>>

>>>> FIND /I "Printer Name"
>>>>
>>>> based on %errorlevel% you can end or add
>>>>
>>>> -J
>>>>
>>>> "Pegasus (MVP)" wrote:


>>>>> On Wednesday, July 30, 2008 10:24 AM Pegasus \(MVP\) wrote:

>>>>> The reg.exe command is not a bit faster than WMI, it
>>>>> is always a lot faster!


>>>>>> On Wednesday, July 30, 2008 1:37 PM JFor wrote:

>>>>>> True! A definite understatement on my part...
>>>>>>
>>>>>> "Pegasus (MVP)" wrote:


>>>>>>> On Sunday, August 03, 2008 6:48 AM aroy wrote:

>>>>>>> On Jul 28, 10:37=A0pm, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
>>>>>>>
>>>>>>> Thanks, best I can find in there is a /q. That hides the little dialog
>>>>>>> box that pops up when the printer is added. That gets the job
>>>>>>> done...sort of. The users are not bothered by the dialog box but, the
>>>>>>> printers are still being installed each time they login regardless of
>>>>>>> whether or not they are already installed.
>>>>>>>
>>>>>>> I would still like to be able to check if the printer is installed on
>>>>>>> the local machine first.
>>>>>>>
>>>>>>> thanks,


>>>>>>>> On Sunday, August 03, 2008 6:48 AM aroy wrote:

>>>>>>>> es" |


>>>>>>>>
>>>>>>>> Excellent thanks all...I am going to try JFords idea today when I get
>>>>>>>> back to the office.


>>>>>>>> Submitted via EggHeadCafe - Software Developer Portal of Choice
>>>>>>>> Review of DevExpress DXperience Control Suite
>>>>>>>> http://www.eggheadcafe.com/tutorials/aspnet/f8ce82a9-d5c2-44fc-91af-e67df5ae502f/review-of-devexpress-dxperience-control-suite.aspx

0 new messages