#188739 - 2008-07-14 07:37 PM
Map Network Printers based on Partial Computer Name
|
jim4flyn
Just in Town
Registered: 2008-07-14
Posts: 2
|
I need to create a script to assign network printers to certain rooms in different buildings. All of our computers are named based on their location. For example for a building I have called BE in room number 105 the first computer would be named be_105_1 and the second be_105_2, etc... I would like to be able to create a script to map a certain printer to all computers with a computer name beginning be_105. Is this possible using a Kix Script?
If not I could alternatively base the script off an OU that houses computer accounts or a domain group that computer accounts are assigned to. So far the only samples I have been able to find though are based on user group memberships, and that will not work in our situation.
Any suggestions or code sample would be appreciated.
Edited by jim4flyn (2008-07-14 07:38 PM)
|
Top
|
|
|
|
#188741 - 2008-07-14 07:51 PM
Re: Map Network Printers based on Partial Computer Name
[Re: jim4flyn]
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Jim,
Do these rooms have specific IPs? If so..
$ip=join(split(@ipaddress0,' '),'')
if LEFT($ip,6)='10.105'
; map a printer
endif
or..
$ip=join(split(@ipaddress0,' '),'')
SELECT
case LEFT($ip,6)='10.105'
; map printer 105
case LEFT($ip,6)='10.106'
; map printer 106
;etc.
ENDSELECT
HTH,
Kent
Edited by Kdyer (2008-07-14 07:52 PM)
|
Top
|
|
|
|
#188744 - 2008-07-14 08:04 PM
Re: Map Network Printers based on Partial Computer Name
[Re: Kdyer]
|
jim4flyn
Just in Town
Registered: 2008-07-14
Posts: 2
|
Thank for your reposes on that. I believe the first example will do what I need. The computers do not have specific IPs based on the room.
|
Top
|
|
|
|
#188748 - 2008-07-14 10:26 PM
Re: Map Network Printers based on Partial Computer Name
[Re: jim4flyn]
|
Björn
Korg Regular
Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
|
a bit late, but just for fun (merged the ideas presented); (NOTE - THIS NEEDS CHECKING (ISN'T EVEN DONE YET :P )
;need to dim vars
Dim $rc
Dim $Location,$Table
Dim $iproom,$ip
Dim $Printer,$DefaultPrinter
Dim $MissingIPprintermapp,$FileShareError
;get the "location"
$Location = Left(@WKSTA, 6)
; printer table is in \\fileserver\share\printertable.ini
; If this is done during a login script, table would be
; \\domain\netlogon\printertable.ini
$Table = '\\fileserver\share\printertable.ini'
;logic should be if cannot read the file, get the error,
if NOT $Printer = ReadProfileString($Table, 'PrinterMapping', $Location)
@SERROR = $FileShareError
else
;else let's set the default printer from it.
$DefaultPrinter=ReadProfileString($Table,'PrinterMapping',split(join$;not done. no brain left. (get the name of the printer)
endif
;now, let's check the room and ip
$iproom=ReadProfileString($Table,'IP-Check',$Location)
$ip=join(split(@ipaddress0,' '),'')
Select
;this case captures if there was an error getting the file
case $FileShareError
'Error! Please report following to you administrator: File share error, ' + @CRLF + $FileShareError ?
;this case catches if the ip and room is a missmatch,
;and could provide the user with the settings to mapp it by "hand"
case $iproom =! $ip
'Something seems to be wrong, contact your administrator,'?
or please enter the name for the printer: ' gets $MissingIPprintermapp ?
$MissingIPprintermapp=rtrim(ltrim($MissingIPprintermapp))
if $MissingIPprintermapp
$rc = AddPrinterConnection('\\printerserver\'+$MissingIPprintermapp)
if $rc
$rc = SetDefaultPrinter($MissingIPprintermapp) ' Setting your printer of choise as default ' ?
else 'error occured! ' + @SERROR + ' ' + @ERROR + ' ' ?
endif
endif
;the nice "default case". If everything worked out, do the mapping
;according to the .ini .
case 1
'Setting up your printer per-default configuration ' ?
If Left(@WKSTA, 6) = $Printer
if NOT $rc = SetDefaultPrinter($DefaultPrinter)
$rc = AddPrinterConnection($Printer)
;Delete the printer.
$rc = DelPrinterConnection($DefaultPrinter)
;Connect the printer.
$rc = AddPrinterConnection($Printer)
;Set the printer as default.
$rc = SetDefaultPrinter($DefaultPrinter)
endif
endif
Else
;Do nothing.
EndIf
EndSelect
/* the ini-file structure
[IP-Check]
be_105=10.105
be_106=10.106
[PrinterMapping]
be_105=\\server\printshare
be_106=\\server\printshare
*/
_________________________
as long as it works - why fix it? If it doesn't work - kix-it!
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 248 anonymous users online.
|
|
|