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

script command for unmapping network printers?

496 views
Skip to first unread message

Rob Gordon

unread,
Jan 13, 2008, 1:34:34 PM1/13/08
to
I am current using a logon script to automatically map network printers
to my user workstation. Th script uses the 'AddPrinter
\\Servername\Printer' command to map a printer to the user's
workstation, but using the 'RemovePrinter' command doesn't seem to work.

Is there an alternative command I should be using to unmap a network
printer from a user's workstation? The workstations in question are
running Windows XP Pro SP2 with all the most current updates.

Pegasus (MVP)

unread,
Jan 13, 2008, 2:04:33 PM1/13/08
to

"Rob Gordon" <Robert...@nospam.dslextreme.com> wrote in message
news:enbuyLhV...@TK2MSFTNGP05.phx.gbl...

Let's have a look at your "RemovePrinter" script! Alternatively
you could use this command:
net use \\Servername\Printername /del


Rob Gordon

unread,
Jan 13, 2008, 2:51:03 PM1/13/08
to Pegasus (MVP)
The commands I'm using are pretty basic (or so I thought)..


Adding a Printer:

if isMember("Domain Users") then
AddPrinter "\\server1\Printer1" ' Create printer1
writeLog "Mapped Printer1"
End if


Removing a Printer:

if isMember("Domain Users") then
RemovePrinter "\\server1\Printer1" ' Remove Printer1
writeLog "Removed Printer1"
End if

Pegasus (MVP)

unread,
Jan 13, 2008, 3:12:20 PM1/13/08
to
I am not aware of an AddPrinter command in VB Script -
is this your own function? If so, let's have a look at it too!
And as I said before - there is a ready-made command
to disconnect network printers.


"Rob Gordon" <Robert...@nospam.dslextreme.com> wrote in message

news:478A6BA7...@nospam.dslextreme.com...

Richard Mueller [MVP]

unread,
Jan 13, 2008, 3:30:48 PM1/13/08
to
Also, you must have your own IsMember function. If so, since most LDAP
attributes and functions to not reveal membership in the "primary" group
(usually Domain Users), it might be that IsMember is returning False when
you expect True.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--

"Pegasus (MVP)" <I....@fly.com.oz> wrote in message
news:%23EP4ZCi...@TK2MSFTNGP05.phx.gbl...

Richard Mueller [MVP]

unread,
Jan 13, 2008, 4:18:31 PM1/13/08
to
You can use the AddWindowsPrinterConnection and RemovePrinterConnection
methods of the wshNetwork object. You can also use the IsMember method of
the group object to check direct group membership. However, this will not
reveal membership due to group nesting, or membership in the "primary"
group. You should assume everyone is a member of "Domain Users". For
example, an Active Directory logon script could be similar to (assuming all
clients are at least Windows 2000):
=====
Option Explicit

Dim objSysInfo, strUserDN, objUser, objNetwork, objGroup

' Bind to local user object.
Set objSysInfo = CreateObject("ADSystemInfo")
strUserDN = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUserDN)

' Bind to wshNetwork object.
Set objNetwork = CreateObject("Wscript.Network")

' Bind to group object to check membership.
Set objGroup = GetObject("LDAP://cn=Sales,ou=West,dc=MyDomain,dc=com")

' Check if user a member of the group.
If (objGroup.IsMember(objUser.AdsPath) = True) Then
' Remove a printer connection.
objNetwork.RemovePrinterConnection "\\MyServer\Laser1", True, True

' Add a printer connection.
objNetwork.AddWindowsPrinterConnection "\\MyServer\Laser3"
' Set default printer.
objNetwork.SetDefaultPrinter "\\MyServer\Laser3"
End If

Rob Gordon

unread,
Jan 13, 2008, 5:17:56 PM1/13/08
to Richard Mueller [MVP]
Yep, the wshNetwork object method using
AddWindowPrinterConnection/RemovePrinterConnection was the route I went.
Worked perfectly.

Thanks much!

Rob

0 new messages