Discussion:
Batch file - add network printers via printui.dll, PrintUIEntry
(too old to reply)
aroy
2008-07-28 22:51:46 UTC
Permalink
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)
2008-07-29 05:37:33 UTC
Permalink
Post by aroy
Greetings all,
I have a client who chooses to deploy printers via their login script.
:: 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?
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.
Have a look at this help command: rundll32 printui.dll,PrintUIEntry /?
aroy
2008-07-29 17:20:32 UTC
Permalink
Post by Pegasus (MVP)
Post by aroy
Greetings all,
I have a client who chooses to deploy printers via their login script.
:: 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?
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.
Have a look at this help command: rundll32 printui.dll,PrintUIEntry /?
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)
2008-07-29 18:46:59 UTC
Permalink
Post by Pegasus (MVP)
Post by aroy
Greetings all,
I have a client who chooses to deploy printers via their login script.
:: 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?
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.
Have a look at this help command: rundll32 printui.dll,PrintUIEntry /?
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,
===========
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
2008-07-30 13:31:01 UTC
Permalink
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
Post by aroy
Post by Pegasus (MVP)
Post by aroy
Greetings all,
I have a client who chooses to deploy printers via their login script.
:: 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?
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.
Have a look at this help command: rundll32 printui.dll,PrintUIEntry /?
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,
===========
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
Pegasus (MVP)
2008-07-30 14:24:34 UTC
Permalink
Post by JFord
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
2008-07-30 17:37:01 UTC
Permalink
True! A definite understatement on my part...
Post by Pegasus (MVP)
Post by JFord
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!
aroy
2008-07-31 14:23:47 UTC
Permalink
Post by J Ford
True! A definite understatement on my part...
Post by Pegasus (MVP)
Post by JFord
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!
Excellent thanks all...I am going to try JFords idea today when I get
back to the office.
Douglas Cowie
2010-10-23 03:16:13 UTC
Permalink
This post might be inappropriate. Click to display it.
Loading...