Page 1 of 1 1
Topic Options
#172658 - 2007-01-11 12:29 AM Using ini file to map printers
SeaSlug Offline
Fresh Scripter

Registered: 2007-01-11
Posts: 9
Hi all,

Noobie here, just learning about Kixtart

Would like some help please.

I need to map a whole bunch of network printers, close to 50. These printers do get updated, and all users need to connect to all of them!

when I run the addprinterconnection, it take a while to map them all, so I wanted to map them only once, but when the admin adds a new printer, they can add it to an ini file and simply update the version number.

So I would have an ini file looking something like

[Version]
Number=1.0

[Printers]
\\pserver\printer1
\\pserver\printer2
\\pserver\printer3
etc to 50

So the admin simply updates the version number both in the ini file and the printer.kix script, and if it is different than the one refered to in the script script, then re-add all the printers.

Likewise, will do the same when pritners are going to be deleted.

Does this make sense?

Any advice and code welcome!

Thank you

Top
#172659 - 2007-01-11 12:32 AM Re: Using ini file to map printers [Re: SeaSlug]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Quote:
Does this make sense?

No.

That is not a properlly formatted INI file. There are no = in the Printers section.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#172660 - 2007-01-11 12:39 AM Re: Using ini file or basic file to map printers [Re: Les]
SeaSlug Offline
Fresh Scripter

Registered: 2007-01-11
Posts: 9
so would I need something like:

[Version]
Number=1.0

[Printers]
1=\\pserver\printer1
2=\\pserver\printer2
3=\\pserver\printer3

taking a different tack, I am also thinking of keeping it simpler??

Have a file called printers.txt for example.
Have all the printers in here.

When logging on, check existing printer connections in the users registry hive.
Read the file entries

Somehow - not sure how compare the two and add or delete those that have been added to or deleted in the file.

Thanks


Edited by SeaSlug (2007-01-11 01:02 AM)

Top
#172662 - 2007-01-11 01:07 AM Re: Using ini file or basic file to map printers [Re: SeaSlug]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Well.. first with the version, I would not use a decimal point.
Second, the [Printers] section I would not have numbered. That way you can enum them.

[Version]
Number=1

[Printers]
\\pserver\printer1=1
\\pserver\printer2=1
\\pserver\printer3=1
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#172664 - 2007-01-11 01:17 AM Re: Using ini file or basic file to map printers [Re: Les]
SeaSlug Offline
Fresh Scripter

Registered: 2007-01-11
Posts: 9
So how would I go about enumerating the [Printers] list and then comparing that with the current list stored in HKCU\Printers\Connections for the user?

thanks \:\)

Top
#172665 - 2007-01-11 01:32 AM Re: Using ini file or basic file to map printers [Re: SeaSlug]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Read in the PrinterPorts from the reg into an array.
Read in the Printers section from the INI into an array.

Search each element of one array against the next.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#172666 - 2007-01-11 01:48 AM Re: Using ini file or basic file to map printers [Re: Les]
SeaSlug Offline
Fresh Scripter

Registered: 2007-01-11
Posts: 9
Yes, that is exactly what I would like to do !!

So, I would create two arrays, then use ASCAN?

do you have any (simple) snippets of code I can use to begin better understanding how this is performed?

thanks in advance


Edited by SeaSlug (2007-01-11 01:50 AM)

Top
#172669 - 2007-01-11 02:17 AM Re: Using ini file or basic file to map printers [Re: SeaSlug]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Code:
Break on

$Index = -1
$RegKey = 'HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts'

Do
$Index = $Index + 1
$PrinterKeys = $PrinterKeys + EnumValue($RegKey, $Index)+CHR(10)
Until @Error

$ArrPrinterKeys = Split($PrinterKeys,CHR(10))


For each $Printer in $ArrPrinterKeys
	$Printer ?
Next
'Hit any key...'
Get $

$ArrPrinters = Split(ReadProfileString('c:\printers.ini','Printers',''),CHR(10))


For each $Printer in $ArrPrinters
	$Printer ?
Next
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#172670 - 2007-01-11 02:42 AM Re: Using ini file or basic file to map printers [Re: Les]
SeaSlug Offline
Fresh Scripter

Registered: 2007-01-11
Posts: 9
Thanks Les

Working on it now.

Neglected to mention that I need to check the users remote printer connections, so am making the changes now.

what I do notice, is that the output from HKCU\Printers\Connections is ,,Server\Printer, yet my ini file is \\server\Printer.

How would I go about changing the reference?

Thanks in advance

Top
#172672 - 2007-01-11 03:00 AM Re: Using ini file or basic file to map printers [Re: SeaSlug]
SeaSlug Offline
Fresh Scripter

Registered: 2007-01-11
Posts: 9
Ah,

When I create the array, I can do a split/join to replace the ,, with \

then continue doing the rest.

Is that correct ?

Thanks

Top
#172673 - 2007-01-11 03:24 AM Re: Using ini file or basic file to map printers [Re: SeaSlug]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Sure, only diff, that reg area has the names in keys not values so you need EnumKey() instead of EnumValue() but you probably already figured that out.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#172674 - 2007-01-11 03:28 AM Re: Using ini file or basic file to map printers [Re: Les]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Code:
Break on

$Index = -1
$RegKey = 'HKEY_CURRENT_USER\Printers\Connections'

Do
$Index = $Index + 1
$PrinterKeys = $PrinterKeys + Join(Split(EnumKey($RegKey, $Index)+CHR(10),','),'\')
Until @Error

$ArrPrinterKeys = Split($PrinterKeys,CHR(10))


For each $Printer in $ArrPrinterKeys
	$Printer ?
Next
'Hit any key...'
Get $

$ArrPrinters = Split(ReadProfileString('c:\printers.ini','Printers',''),CHR(10))


For each $Printer in $ArrPrinters
	$Printer ?
Next
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#172675 - 2007-01-11 04:41 AM Re: Using ini file or basic file to map printers [Re: Les]
SeaSlug Offline
Fresh Scripter

Registered: 2007-01-11
Posts: 9
Hi Les,

Yeap figured that one out with the keys/value.

What I couldn't figure was the split, join. I had it in the wrong spot

So far so good.

Last step, how do I go about comparing between the two arrays?
Would I use ASCAN and check for the existance of the variable from the ini file against the registry array?

thanks for all your help so far!


Edited by SeaSlug (2007-01-11 05:21 AM)

Top
#172676 - 2007-01-11 05:30 AM Re: Using ini file or basic file to map printers [Re: SeaSlug]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Well, this should compare the INI to the reg and add it if missing.
Code:
For each $Printer in $ArrPrinters
	$Printer ?
	If AScan($ArrPrinterKeys,$Printer) = -1
		$RC = AddPrinterConnection($Printer)
	EndIf
Next

You still need to do the same thing the other way around comparing the reg to the INI to delete what is not in the INI.

Remember this this is all optimistic code. You still need to add error checking etc.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#172677 - 2007-01-11 05:49 AM Re: Using ini file or basic file to map printers [Re: Les]
SeaSlug Offline
Fresh Scripter

Registered: 2007-01-11
Posts: 9
I managed to get something similiar going, though nowhere as elegant as yours.

I will incorporate your code into my script to make it look a bit better. Will help the admins out greatly that they only have to change 1 file to update the printers.

I agree with your logging comments, once I get the basic theory going, then I will work on the logging.

I can't thank you enough for helping me out
BIG Double thumbs up to ya !! Your a legend !

BTW - what does the $RC = do ? Does that catch any output?

Thanks again.

Top
#172679 - 2007-01-11 06:26 AM Re: Using ini file or basic file to map printers [Re: SeaSlug]
SeaSlug Offline
Fresh Scripter

Registered: 2007-01-11
Posts: 9
I noticed that when I do my check for the registry array contents against the ini file array, there appears to be 2 blank lines (cr/lf perhaps) that cause 2 errors to occur.

Any ideas?

Top
#172697 - 2007-01-11 07:39 PM Re: Using ini file or basic file to map printers [Re: SeaSlug]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
The $RC does just that, capture the return code that would otherwise fall out onto the floor. As I said, very optimistic code simply to demonstrate the basics. You will need to handle the null array elements.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

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 248 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.071 seconds in which 0.024 seconds were spent on a total of 13 queries. Zlib compression enabled.

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