#176941 - 2007-06-13 09:13 AM
Question :How to use an extra configuration file?
|
mikeemikee
Fresh Scripter
Registered: 2007-06-12
Posts: 23
Loc: Germany, Hildesheim
|
Hello,
I hope someone can help me in the following situation. I have inserted some lines of code, that I want to act as a printer-add-script. The script runs without problems.
Following question:
I want to create a special configuration file, that holds all dynamic variables and arrays.
Could anyone please help me?
Regards Stefan
;DEBUG ON
;BREAK ON
DIM $groups
DIM $printers
DIM $printserver
DIM $grp
DIM $prt
DIM $stdrck
DIM $stdgrp
DIM $EDV_print
DIM $EDV_drucker
DIM $SD_print
DIM $SD_drucker
$printserver = \\ps02\
$groups = "domain\EDV_print","domain\SD_print"
$EDV_drucker = "DV-HPBJ1100","DV-HPCL5550"
$SD_drucker = "SD1-HPLJ4P","SD2-HPLJ4P"
$stdrck = "DV-HPBJ1100","DV-HPCL5550","DV-HPDJ1050C","DV-HPLJ2200"
FOR EACH $grp IN $groups
SELECT
CASE $grp = "nlkhhi\EDV_print"
$printers = $EDV_drucker
CASE $grp = "nlkhhi\SD_print"
$printers = $SD_drucker
ENDSELECT
? "Vor Schleife 2"
FOR EACH $prt IN $printers
IF Ingroup("$grp")
? "-------------------------"
delprinterconnection ("$printserver$prt")
addprinterconnection ("$printserver$prt")
ELSE
ENDIF
NEXT
NEXT
FOR EACH $stdgrp in $stdrck
IF INGROUP("$stdgrp")
Setdefaultprinter ("$printserver$stdgrp")
ENDIF
NEXT
:Exit
flushkb
EXIT 1
Edited by mikeemikee (2007-06-13 09:46 AM)
|
|
Top
|
|
|
|
#176958 - 2007-06-13 04:34 PM
Re: Use of an extra configuration file
[Re: Richard H.]
|
mikeemikee
Fresh Scripter
Registered: 2007-06-12
Posts: 23
Loc: Germany, Hildesheim
|
Hi Richard,
thank you very much for you support. Could you please me point me to some results, that show me how use the readprofile() function? regards Stefan
|
|
Top
|
|
|
|
#176959 - 2007-06-13 05:05 PM
Re: Use of an extra configuration file
[Re: mikeemikee]
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Here is one: http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=132911&page=0&fpart=1
It is quite long but it goes through most of the steps that you will be taking.
To find more results (and there are many!) do this:
- Click on the "Search" link at the top of the page.
- Select "All Forums" to search
- Select some relevant keywords, for example "+group +printer +map +readprofilestring"
- In the "Date Range" clear the "Newer than" fields, and enter "1 day" in the "Older than" fields"
You should get a big result list. Not all of the results will be useful, but most will.
You can also try limiting the search to the UDF forum, to see if there is a ready made function that will work for you.
|
|
Top
|
|
|
|
#177276 - 2007-06-27 09:22 AM
Re: Use of an extra configuration file
[Re: Richard H.]
|
mikeemikee
Fresh Scripter
Registered: 2007-06-12
Posts: 23
Loc: Germany, Hildesheim
|
Here is a modified kix-script, that maps printers, defined in a ini-file.
sequence of the script: 1. saving the default printer in a variable 2. deleting all mapped printers 3. mapping printers by group membership 4. restoring the default printer
;Script Options
;Break ON
CLS
;;;;;;;;;;;;;;;;;;;;;;;;;Funktionen;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Funktion "Standarddrucker"
Function GetDefaultPrinter()
$GetDefaultPrinter = Join(Split(ReadValue("HKEY_USERS\"+@SID+"\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device"),',',1),'')
EndFunction
;Funktion "Zeichersetzung"
Function Replace($SourceString,$ChrToReplace,$ReplacementChr)
$Array = Split($SourceString,$ChrToReplace,-1)
For Each $Element In $Array
$Replace = $Replace + $Element + $ReplacementChr
Next
$Replace=substr($Replace,1,len($Replace)-1)
ENDFUNCTION
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Break on
; Überprüfung, ob eine Druckermapping für die Gruppe da ist.
$bDEBUG=0
$sPrinterIni= @SCRIPTDIR + "\PrinterMap.ini"
If ReadProfileString($sPrinterIni,"","")
If $bDEBUG
"DEBUG: Die folgenden Sektionen erscheinen in der INI.-Datei:" ?
"-----------------------------------------------------" ?
ReadProfileString($sPrinterIni,"","")
"-----------------------------------------------------" ?
EndIf
Else
If Exist($sPrinterIni)
"ERROR: INI-Datei '"+$sPrinterIni+"' ist leer oder ungültig!" ?
Else
"ERROR: INI-Datei '"+$sPrinterIni+"' existiert nicht!" ?
EndIf
Exit 1
EndIf
; Zwischenspeicherns des Standarddruckers
DIM $DefaultPrinter
$DefaultPrinter=GetDefaultPrinter()
; AUfruf der Funktion ""Drucker entfernen"
"Entferne bestehende Druckerverbindungen ..." @CRLF
DIM $IdxNum
$IdxNum = 0
:Loop1
$PrnPath = EnumKey("HKEY_CURRENT_USER\Printers\connections\", $IdxNum)
If @ERROR = 0
$PrnPath = Replace($PrnPath,",","\")
$rs = DelPrinterConnection ($PrnPath)
? $IdxNum
? $PrnPath
$IdxNum = $IdxNum + 1
GoTo Loop1
EndIf
@CRLF "Fertig." @CRLF
$iIndex=0
$iDefaultDone=0
$sGroup=EnumGroup($iIndex)
While $sGroup AND Not @FEHLER
; Wegfallenlassen des Domainteils nlkhhi\
If InStr($sGroup,"\") $sGroup=SubStr($sGroup,InStr($sGroup,"\")+1) EndIf
If $bDEBUG Color w+/b "DEBUG: Looking for section [LOCATION "+$sGroup+"]" Color w/n ? EndIf
; Überprüfung, ob ein Druckermapping für die Gruppe da ist.
For Each $sPrinter in Split(ReadProfileString($sPrinterIni,"LOCATION "+$sGroup,""),Chr(10))
If $sPrinter
$asPrinterPair=Split(ReadProfileString($sPrinterIni,"LOCATION "+$sGroup,$sPrinter),"|")
"Mappe primären Druckerpfad "+$asPrinterPair[0]
If AddPrinterConnection($asPrinterPair[0])
" " Color r+/n "*Fehlgeschlagen*" Color w/n @CRLF
"Mappe alternativen Druckerpfad "+$asPrinterPair[1]
If AddPrinterConnection($asPrinterPair[1])
" " Color r+/n "*Ebenfalls Fehlgeschlagen*" Color w/n @CRLF
"Grund: ["+@ERROR+"] "+@SERROR+@CRLF
Else
" " Color g+/n "OK" Color w/n @CRLF
EndIf
Else
" " Color g+/n "OK" Color w/n @CRLF
EndIf
EndIf
Next
$iIndex=$iIndex+1
$sGroup=EnumGroup($iIndex)
Loop
; Setzen des originären Standarddruckers
IF SETDEFAULTPRINTER ("$DefaultPrinter") = 0
? Color b+/n "Der Standarddrucker lautet= $DefaultPrinter ." @CRLF
ELSE
? "Beim Setzen des Standarddrucker ist ein Fehler aufgetreten."
ENDIF
Exit 0
printmap.ini
[LOCATION EDV_print]
DV-HPBJ1100=\\ps02\DV-HPBJ1100|\\ps01\DV-HPBJ1100
DV-HPCL5550=\\ps02\DV-HPCL5550|\\ps01\DV-HPCL5550
Edited by mikeemikee (2007-07-03 10:31 AM)
|
|
Top
|
|
|
|
#177485 - 2007-07-03 10:47 AM
Mapping of network shares with an ini-file
[Re: mikeemikee]
|
mikeemikee
Fresh Scripter
Registered: 2007-06-12
Posts: 23
Loc: Germany, Hildesheim
|
Following modified code maps network shares. A definition file netmap.ini holds the necessary data.
;Script Options
;Break ON
CLS
$bDEBUG=1
$sShareIni= @SCRIPTDIR + "\NetMap.ini"
If ReadProfileString($sShareIni,"","")
If $bDEBUG
"DEBUG: Die folgenden Sektionen erscheinen in der INI.-Datei:" ?
"-----------------------------------------------------" ?
ReadProfileString($sShareIni,"","")
"-----------------------------------------------------" ?
EndIf
Else
If Exist($sShareIni)
"ERROR: INI-Datei '"+$sShareIni+"' ist leer oder ungültig!" ?
Else
"ERROR: INI-Datei '"+$sShareIni+"' existiert nicht!" ?
EndIf
Exit 1
EndIf
Use * /delete
$iIndex=0
$iDefaultDone=0
$sGroup=EnumGroup($iIndex)
While $sGroup AND Not @FEHLER
; Wegfallenlassen des Domainteils nlkhhi\
If InStr($sGroup,"\") $sGroup=SubStr($sGroup,InStr($sGroup,"\")+1) EndIf
If $bDEBUG Color w+/b "DEBUG: Looking for section [LOCATION "+$sGroup+"]" Color w/n ? EndIf
; Überprüfung, ob eine Netzwerkmapping für die Gruppe da ist.
For Each $sShare in Split(ReadProfileString($sShareIni,"LOCATION "+$sGroup,""),Chr(10))
If $sShare
$asSharePair=Split(ReadProfileString($sShareIni,"LOCATION "+$sGroup,$sShare),"|")
DIM $Befehl1
$Befehl1 = $asSharePair[0]+$asSharePair[1]
DIM $Befehl2
$Befehl2= $asSharePair[0]+$asSharePair[2]
"Mappe alternativen Netzwerkpfad "+$asSharePair[1]+" auf "+$asSharePair[0] @CRLF
If Execute( 'USE $Befehl1' )
" " Color r+/n "*Fehlgeschlagen*" Color w/n @CRLF
"Mappe alternativen Netzwerkpfad "+$asSharePair[2]+" auf "+$asSharePair[0] @CRLF
If Execute( 'USE $Befehl2' )
" " Color r+/n "*Ebenfalls Fehlgeschlagen*" Color w/n @CRLF
"Grund: ["+@ERROR+"] "+@SERROR+@CRLF
Else
" " Color g+/n "OK" Color w/n @CRLF
EndIf
Else
" " Color g+/n "OK" Color w/n @CRLF
EndIf
EndIf
Next
$iIndex=$iIndex+1
$sGroup=EnumGroup($iIndex)
Loop
Exit 0
netmap.ini ! caution: the delimiter '|' is followed by a blank !
[LOCATION AD_map]
ad=W:| "\\FS03\Daten"| "\\FS02\Daten"
Edited by mikeemikee (2007-07-03 10:53 AM)
|
|
Top
|
|
|
|
#177508 - 2007-07-03 03:43 PM
Re: Mapping of network shares with an ini-file
[Re: Lonkero]
|
mikeemikee
Fresh Scripter
Registered: 2007-06-12
Posts: 23
Loc: Germany, Hildesheim
|
so, if default printer is network printer that you don't map back?
-> the default printer is restored after installing the printers. or I am missing the point?
|
|
Top
|
|
|
|
#177531 - 2007-07-03 09:16 PM
Re: Mapping of network shares with an ini-file
[Re: Lonkero]
|
mikeemikee
Fresh Scripter
Registered: 2007-06-12
Posts: 23
Loc: Germany, Hildesheim
|
I see, you are right, that type of printers would not come back. there are a hand full of computers with a local printerqueue, but luckily only administrative user can remove them.
in my case, the logic runs fine.
however, thanks for your useful interjection.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1046 anonymous users online.
|
|
|