From: francois on
francois a �crit :

>> I would like to add a network printer connection to a XP client with a
>> logon script, but *without* store the mapping in the use profile. Is
>> it possible ?
>
> Has anybody got an idea about this?
>
> I use roaming profiles and in the logon script I use the
> AddWindowsPrinterConnection method which stores the mapping in the
> profile. It causes some problem to me. :-)

Well..., I have not found solutions for the moment.
If you know a way to connect a network printer without
storing the mapping in the user profile, I'll be very
interesting. :-)


So, while waiting for a solution to this problem, I'm using
a way to avoid it. I have created a function, called
"connectPrinters(param)" which takes one string parameter
such as :

param = "\\SRV\Brother1|\\SRV\EPSON3|\\SRV\SAMSUNG1"

and, in this case, the "connectPrinters(param)" command :

1) installs the printer contained in "param"
2) disconnects the printers stored in the user profile which
are not contained in "param"
3) sets the first printer in "param" to the default printer




'-------------------------------------
Sub ConnectPrinters(list)

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oPrinters = WshNetwork.EnumPrinterConnections()

'If list is an empty string, we remove all the printer
If list = "" Then
For i = 0 To oPrinters.length-1 Step 2
printerName = UCase(oPrinters.Item(i+1))
'Wscript.Echo "On d�sintalle l'imprimante : " &
printerName
Call
WshNetwork.RemovePrinterConnection(printerName, True, True)
Next
Exit Sub
End If

'Else (list is not empty), there are 3 parts
seq_printers = Split(list, "|")

'Part 1: we create a dictionary which, for each printer
'in list, associates the False value, it means that the
'printer is not already installed
Set Dict_IsInstalled = CreateObject("Scripting.Dictionary")
For Each printer In seq_printers
printer = UCase(printer)
Call Dict_IsInstalled.Add(printer, False)
Next

'Part 2: for each already installed printer, if it is
'contained in the dictionary, we set the value on True,
'else we remove the printer
For i = 0 To oPrinters.length-1 Step 2
printerName = UCase(oPrinters.Item(i+1))
If Dict_IsInstalled.Exists(printerName) Then
Dict_IsInstalled.Item(printerName) = True
Else
'Wscript.Echo "On d�sintalle l'imprimante : " &
printerName
Call
WshNetwork.RemovePrinterConnection(printerName, True, True)
End If
Next

'Part 3: for each printer in the dictionary, if the
'associated value is False, we install the printer,
'else we do nothing because the printer is already
'installed
For Each printerName In Dict_IsInstalled.Keys
If Dict_IsInstalled.Item(printerName) Then
'we do nothing
Else
'Wscript.Echo "On intalle l'imprimante : " &
printerName
Call
WshNetwork.AddWindowsPrinterConnection(printerName)
End If
Next

'Finally, we set the default printer on the first printer
'in the list
DefaultPrinterName = UCase(seq_printers(0))
'Wscript.Echo DefaultPrinterName & " devient
l'imprimante par d�faut"
Call WshNetwork.SetDefaultPrinter(DefaultPrinterName)

End Sub
'-------------------------------------



--
Fran�ois Lafont