Page 1 of 1 1
Topic Options
#168006 - 2006-09-18 04:53 AM How to get a list of printers but requires security
Mark Pietersz Offline
Getting the hang of it

Registered: 2001-09-30
Posts: 74
Loc: Melbourne, Australia
Hi Team

I am trying create a login script that will add printer queues for a client PC when the user logs in. I have used the UDF PrinterList() from Allen Powell which works well when I am logged in as a user with permissions to interrogate the print server. However when I run as a domain user the code falls over on

$Service = GetObject("winmgmts:\\" + $remotepc + "\root\cimv2")

I guess I need to execute the code as a priviledged user account on the print server. I have found the following code on MSDN

$wbemImpersonationLevelImpersonate = 3
$wbemAuthenticationLevelPktPrivacy = 6

$objLocator = CreateObject("WbemScripting.SWbemLocator")
$objService = objLocator.ConnectServer("TargetComputer", "root\cimv2", "UserName", "Password")
objService.Security_.ImpersonationLevel = $wbemImpersonationLevelImpersonate
objservices.Security_.AuthenticationLevel = $wbemAuthenticationLevelPktPrivacy

This suggests that I can connect as another user but the code fails after
objService.Security_.ImpersonationLevel = $wbemImpersonationLevelImpersonate

Am I barking up the wrong tree ? is there a better way ?

I would also need to know the minimum priviledges required to execute

$Printers=$service.execquery ('select * from Win32_Printer')


TIA

Mark

Top
#168007 - 2006-09-18 05:26 AM Re: How to get a list of printers but requires security
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
Just for clarification... when the limited user runs the script, are you trying to use Printerlist() locally or on a remote pc that they don't have permissions on.
Top
#168008 - 2006-09-18 07:37 AM Re: How to get a list of printers but requires security
Mark Pietersz Offline
Getting the hang of it

Registered: 2001-09-30
Posts: 74
Loc: Melbourne, Australia
Hi Allan

(note: PrinterList() and PriMapState() have been sourced from the Kix UDF library)

You are correct.

Our network users typically don't have have much more than Domain User access. When they login we want the script to interrogate the users print server (a remote pc) and then add those printers to their desktop config.

This is another piece of code that I have found on the BBS

for each $share in listPrinterShares($computer)
$share ?
next

function listPrinterShares(optional $computer)
dim $share,$shares,$a[0]
$a[0] = "PrintQueue"
if not vartype($computer) $computer=@wksta endif
$computer = getobject("WinNT://"+$computer+",Computer")
$computer.filter=$a
if @error exit @error endif
for each $share in $computer
redim preserve $shares[ubound($shares)+1]
$shares[ubound($shares)] = $share.name
next
$listPrinterShares = $shares
endfunction

This gets the list of printer shares without having the security issue however it returns the share name of the printer. When the share name of the printer is passed to PriMapState() it can return null if the printer name and the printer share name are not the same. My script will try to add the printer again. Eg the share name for a printer is \\PSAUMEL1\Xerox84000 but its printer name is \\PSAUMEL1\Xerox Phaser 8400DP

For this reason PrinterList() is nicer.

Can PrinterList() be updated so that it can work where $remotepc is a print server on a network and the calling user has limited network priviledges ?
For my purposes the solution can involve the creation of a dedicated account on the print server to perform winmgmts: call.

The functional part of my code is

? 'Getting the list of printers from print server: ' + $remotepc
$array=printerlist($remotepc)

for each $printer in $array

$printer = '\\' + $remotepc + '\' + $printer
$x = PriMapState($printer)

if $x = ""
? 'Adding printer: ' + $printer
addprinterconnection ($printer)
endif

next

Regards Mark

Top
#168009 - 2006-09-18 08:17 AM Re: How to get a list of printers but requires security
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
Hi Mark,

Please use the CODE TAGS when posting more than about one or two lines of code.

Reading multiple lines of code without formatting is a pain.

Thanks again guy.

Top
#168010 - 2006-09-18 09:22 AM Re: How to get a list of printers but requires security
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
I'll see what I can do to update printerlist, but in the mean time you might try seeing if this will help.

Change this line
Code:
 $shares[ubound($shares)] = $share.name  


to
Code:
 $shares[ubound($shares)] = $share.printerpath 



Let me know if this helps.

Top
#168011 - 2006-09-18 09:45 AM Re: How to get a list of printers but requires security
Mark Pietersz Offline
Getting the hang of it

Registered: 2001-09-30
Posts: 74
Loc: Melbourne, Australia
Hi Allan

You suggestion was not successful however it did prompt me to try $share.printername which looks like it might do the trick. I'll be able to try this out tomorrow. This leads me to another question.

What are the merits of using a
$Service = GetObject("winmgmts:\\" + $remotepc + "\root\cimv2")
approach rather than
$computer = getobject("WinNT://"+$computer+",Computer")

And sorry for forgetting to properly format my posted code

Cheers

Mark
_________________________
Mark Pietersz

Top
#168012 - 2006-09-19 06:02 AM Re: How to get a list of printers but requires security
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Why can you not give the users access to the remote computer via their domain accounts? Also, see the fnWMIAuthentication() - Authenticates against a local or remote WMI provider UDF
_________________________
There are two types of vessels, submarines and targets.

Top
#168013 - 2006-09-22 03:37 AM Re: How to get a list of printers but requires security
Mark Pietersz Offline
Getting the hang of it

Registered: 2001-09-30
Posts: 74
Loc: Melbourne, Australia
hi Guys

Jens - the remote computers are servers that store sensitive information as well as acting as print servers. If a give enough access via WMI authentication to allow

$service.execquery ('select * from Win32_Printer') by users would I be in danger of giving members of the Domain Users group to much access to the machine ?

Mark

Top
#168014 - 2006-09-22 06:38 AM Re: How to get a list of printers but requires security
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Why don't you configure the server's securty such that users can only use the print serer functionality? Alternatively, get a dedicated print server if you're so concerned about inadvertanly exposing the sensitive information.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1045 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.06 seconds in which 0.028 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org