Page 1 of 1 1
Topic Options
#34463 - 2002-12-11 07:29 PM Removing Printers using INI file
Grasshopper Offline
Fresh Scripter

Registered: 2002-11-29
Posts: 15
Loc: London, UK
I have implemented the script below to add printer connections based on a users floor but now have the need to remove printers if the user moves floors

code:
$PRTserver=sthfs2
$regkey="HKCU\Printers\Connections\,,"+$PRTserver+","+$printer ;Registry key for printer connections
$levels=ReadProfileString('@CURDIR\printers.ini','','') ;Read printers.ini string
$levels=Split($levels,Chr(10))
ReDim preserve $levels[Ubound($levels)-1]
For Each $level in $levels ;Split results
If InGroup ("@DOMAIN\"+$level)= 1 ;Check for group membership
If KeyExist($regkey) ;Check if printer already connected
? "Printer already connected"
Else
$printers=ReadProfileString('@CURDIR\printers.ini',$level,'Printers')
$printers=Split($printers,',')
For Each $printer in $printers
$nul=AddPrinterConnection("\\$PRTserver\"+$printer)
Next
EndIf
Else
EndIf
Next

INI File -------------------------------------

[Level 1 Printers]
Printers=1FLR_PRT1_HP4100_BW_A4

[Level 2 Printers]
Printers=2FLR_PRT1_SHC250_COL_A3

[Level 3 Printers]
Printers=3FLR_PRT1_HP4100_BW_A4

[Level 8 Printers]
Printers=8FLR_PRT1_HP4050_BW_A4

Basically, if a user was in 1st floor group and now moves to the 2nd floor group I want to read the INI file and remove all printer connections from the old group and remap to the new group. I only want to add printers once. I want to avoid deleting and adding printers on each login. The situation I have at the moment is if the user moves floors they end up with both floors printers.

Any ideas ?

Cheers,
Grasshopper
_________________________
Just Another Aussie on Tour !

Top
#34464 - 2002-12-11 07:31 PM Re: Removing Printers using INI file
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
See UnmapPrinters() - Removes mapped printers not listed in an .INI file
_________________________
There are two types of vessels, submarines and targets.

Top
#34465 - 2002-12-11 07:38 PM Re: Removing Printers using INI file
Grasshopper Offline
Fresh Scripter

Registered: 2002-11-29
Posts: 15
Loc: London, UK
This looks OK but how can I extend it to remove printers based on sections within the INI file ?

eg. Bob moves from floor 1 to 2, has 1st floor printers currently. Remove Bob from Level 1 Group, add him to Level 2 group. Bob logs in, script removes level 1 printers and adds level 2 printers based on one INI file.

I have a feeling I might have to create another group ????????
_________________________
Just Another Aussie on Tour !

Top
#34466 - 2002-12-11 07:43 PM Re: Removing Printers using INI file
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
The UDF removes any printer for which the user is not a member of. Thus create groups like 'Floor1', 'Floor2'. And please take a look at the required .INI file structure.
_________________________
There are two types of vessels, submarines and targets.

Top
#34467 - 2002-12-11 07:55 PM Re: Removing Printers using INI file
Grasshopper Offline
Fresh Scripter

Registered: 2002-11-29
Posts: 15
Loc: London, UK
Sorry Jens, I don't quite understand your entire script, I get parts of it. The section names in my INI file are also the NT group names of which the user must be a part of to map the printers within each section. What will I need to modify in your script to unmap the printers without changing the section names of the INI file ?
_________________________
Just Another Aussie on Tour !

Top
#34468 - 2002-12-11 08:22 PM Re: Removing Printers using INI file
Grasshopper Offline
Fresh Scripter

Registered: 2002-11-29
Posts: 15
Loc: London, UK
Also, how easy would it be to remove a printer if the user is in the correct group though the printer no longer exists based on my current INI format ?
_________________________
Just Another Aussie on Tour !

Top
#34469 - 2002-12-11 08:29 PM Re: Removing Printers using INI file
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
My UDF deletes printers that are not listed in the .INI file.

You will need to rework all of the section/key readers to read the different format.
_________________________
There are two types of vessels, submarines and targets.

Top
#34470 - 2002-12-11 08:39 PM Re: Removing Printers using INI file
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Maybe I don't understand exactly what you need to do, but why can't you do something like this

code:
  
For Each $level in $levels ;Split results
If InGroup ("@DOMAIN\"+$level)= 1 ;Check for group membership
If KeyExist($regkey) ;Check if printer already connected
? "Printer already connected"
Else
$printers=ReadProfileString('@CURDIR\printers.ini',$level,'Printers')
$printers=Split($printers,',')
For Each $printer in $printers
$nul=AddPrinterConnection("\\$PRTserver\"+$printer)
Next
EndIf
Else
; Psuedocode
if user is connected to this group's printer (from ini file)
remove it
endif
Endif
Next

_________________________
Eric

Top
#34471 - 2002-12-11 08:48 PM Re: Removing Printers using INI file
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
This way you will not be able to distribute updated printer dirvers.
_________________________
There are two types of vessels, submarines and targets.

Top
#34472 - 2002-12-11 08:49 PM Re: Removing Printers using INI file
Grasshopper Offline
Fresh Scripter

Registered: 2002-11-29
Posts: 15
Loc: London, UK
It seems you have a better idea of what i need to do than I do ! Why did you have to make it seem so simple !! I can't believe I couldn't think of a simple thing like that. I guess I was getting too caught up in it all.

Thanks.

Grasshopper
_________________________
Just Another Aussie on Tour !

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 871 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.127 seconds in which 0.093 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