#198082 - 2010-03-17 02:56 AM
Easy help with printer kix i found
|
metatron
Fresh Scripter
Registered: 2008-05-06
Posts: 27
Loc: london
|
hi
can anyone tell me how i can get this script to map a printer if it has a space in between the words that make up its name?
here is the code for the script
Select
Case InGroup( 'Logon A' )
$sPrinterList='\\apple\BW \\apple\BW colour'
Case 1 ; catch all, clear printerlist
$sPrinterList = ''
EndSelect
If $sPrinterList ; if sPrinterList is defined, perform this logic
For Each $sPrinter in Split($sPrinterList)
'Checking printer ' + $sPrinter + @CRLF
If PriMapState($sPrinter)
' Already connected' + @CRLF
Else
' Connecting...' + @CRLF
If AddPrinterConnection($sPrinter)
' **Error connecting: [' + @ERROR + '] ' + @SERROR + @CRLF
Else
' Success!' + @CRLF
EndIf
EndIf
Next
EndIf
Exit 0
very easy to many, a long time and sore eyes for me thanks
Edited by Richard H. (2010-03-18 02:26 PM) Edit Reason: Added code tags
|
|
Top
|
|
|
|
#198126 - 2010-03-22 02:55 PM
Re: Easy help with printer kix i found
[Re: Allen]
|
metatron
Fresh Scripter
Registered: 2008-05-06
Posts: 27
Loc: london
|
so all i needed was a comma? damnit thanks for your help allen and sorry about the code paste
|
|
Top
|
|
|
|
#198127 - 2010-03-22 04:02 PM
Re: Easy help with printer kix i found
[Re: metatron]
|
Arend_
MM club member
   
Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
|
And if you really want to split it into a proper array, tell split what it should split.
$string1 = "printer1","printer2"
$string2 = "printer1" "printer2"
$array1 = Split($string1,",")
$array2 = Split($string2," ")
|
|
Top
|
|
|
|
#198128 - 2010-03-22 07:03 PM
Re: Easy help with printer kix i found
[Re: Arend_]
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4567
Loc: USA
|
Arend, you might want to check that code out... I don't think its going to work the way you have it.
|
|
Top
|
|
|
|
#198764 - 2010-06-02 01:30 PM
Re: Easy help with printer kix i found
[Re: Co]
|
Mart
KiX Supporter
   
Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
|
The code below is DEMO code. It might be a bit dummy proof with variable names and stuff but I'm not the only one using this in our company and the others might be less skilled in kixtart so I made it easy to understand for everyone.
It requires some UDF's ARRAYENUMKEY() - Creates an array of names of the subkeys contained in a registry key PriMapState() - Checks for existent printerconnection And the one below (not in UDF section).
;Region Check printer logfile
;Set printer log file name
$printerlog = "C:\somefolder\Printers.ini"
;Check if the printer log file exists.
If Exist ($printerlog)
;Delete old printer log file.
Del $printerlog
;Create printer log file.
$rc = CreateFile($printerlog)
Else
;Create printer log file.
$rc = CreateFile($printerlog)
EndIf
;endregion
;Region Set variables
;Set name of the printerserver
$printerserver = "Server"
;Get all installed network printers.
;Set the key that should be enumerated.
$key = "HKCU\Printers\Connections"
;Enumerate network printers key.
$oldprinters = ArrayEnumKey($key)
;Do stuff for each value
For Each $value in $oldprinters
;Split the value on the comma.
$value = Split($value, ",")
;Put the value back together so that is represents the correct path to the printer.
$value1 = "\\"+ $value[2] + "\" + $value[3]
;Add the created value to a variable to be writiine to the printer log file.
$oldprinter = $oldprinter + "~" + $value1
Next
;Write all old printers to the printer log file.
$rc = WriteProfileString($printerlog, "Printers", "OldPrinters", $oldprinter)
$currentprinters = Split($oldprinter, "~")
;endregion
;Region Add printers
;Set printer name.
$printer = "\\" + $printerserver + "\Printer"
;Check group membership.
If InGroup("SomeName-Default") Or InGroup("SomeName-Extra")
;Check if the printer is already installed.
If Not PriMapState($printer)
;Printer is not installed. Add printer.
$rc = AddPrinterConnection($printer)
EndIf
;Read all so far installed printers from the printer log file.
$connected = ReadProfileString($printerlog, "Printers", "NewPrinters")
;Add the printer name to a variable to be written to the printer log file.
$connected = $connected + "~" + $printer
;Write the new printers value to the printers log file.
$rc = WriteProfileString($printerlog, "Printers","NewPrinters",$connected)
EndIf
;Region Set default printer
;Check group membership.
If InGroup("SomeName-Default")
$printer = "\\" + $printerserver + "\Printer"
;Check if the printer is already set as default.
If PriMapState($printer) <> "2"
;Set default printer.
$rc = SetDefaultPrinter($printer)
EndIf
EndIf
;Region Clean printers
;Read all old network printers from the printer log file.
$oldprinters = ReadProfileString($printerlog, "Printers", "OldPrinters")
;Check if there are any old printers in the list.
If $oldprinters <> ""
;Split the old printers on the ~ character
$oldprinters = Split($oldprinters, "~")
EndIf
;Check each element of the array.
For $i = 0 to UBound($oldprinters)
;Remove extra ~ characters.
$oldprinters[$i] = Join(Split($oldprinters[$i], "~"),"")
Next
;Read all new printers from the printer log file.
$newprinters = ReadProfileString($printerlog, "Printers", "NewPrinters")
;Check if there are any new printers in the list.
If $newprinters <> ""
;Split the new printers on the ~ character
$newprinters = Split($newprinters, "~")
EndIf
;Check each element of the array.
For $i = 0 to UBound($newprinters)
;Remove extra ~ characters.
$newprinters[$i] = Join(Split($newprinters[$i], "~"), "")
Next
;Compare the list of old and new printers.
$tobedeletedprinters = ArrayComp($newprinters, $oldprinters)
;Check if there are any printers that should be deleted.
If UBound($tobedeletedprinters) > -1
For Each $tobedeletedprinter in $tobedeletedprinters
;Delete each printer that should be deleted.
$rc = DelPrinterConnection($tobedeletedprinter)
Next
EndIf
;endregion
CreateFile() UDF:
Function CreateFile($file)
Dim $newFolder, $NewFile, $fso
$fso = CreateObject("Scripting.FileSystemObject")
$NewFile = $fso.CreateTextFile($file, True)
$NewFile.Close
EndFunction
_________________________
Mart
- Chuck Norris once sold ebay to ebay on ebay.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 580 anonymous users online.
|
|
|