#197275 - 2010-01-05 02:36 PM
Re: Adding Printers separating groups
[Re: BradV]
|
Valentim
Fresh Scripter
Registered: 2010-01-04
Posts: 46
Loc: Brazil, PE, Recife
|
Hi BradV,
Yeah, He just gave me a code where I would have to create a "If InGroup (GroupX)" for each existing group.
Through this code he gave me this could create code that automatically gets all the groups, keys and values of the ini file
;================================================================
;= Function : ENumGroupIni
;= Author : Roberto Valentim
;= Example(s) : ENumGroupIni("C:\print.ini")
;================================================================
Function ENumGroupIni($file)
;================================================================
DIM $GrpArray, $Grupo, $GrpChave, $Chave, $Valores, $Valor
$GrpArray = split(readprofilestring($file, '', ''), chr(10))
For Each $Grupo in $GrpArray
If ($Grupo <> "")
If InGroup($Grupo)
; ? "Grupo >> " + $Grupo
$GrpChave = split(readprofilestring($file, $Grupo, ''), chr(10))
For Each $Chave in $GrpChave
If ($Chave = "Printers")
; ? " Chave >> " + $Chave
$Valores = split(readprofilestring($file, $Grupo, $Chave), ",")
For Each $Valor in $Valores
AddPrinterConnection("\\srv-jbgarq03\" + $Valor)
; ? " Printers >> " + $Valor
Next
EndIf
If ($Chave = "Default")
; ? " Chave >> " + $Chave
$Valores = split(readprofilestring($file, $Grupo, $Chave), ",")
For Each $Valor in $Valores
SetDefaultPrinter("\\srv-jbgarq03\" + $Valor) = 0
; ? " Default >> " + $Valor
Next
EndIf
Next
EndIf
EndIf
Next
EndFunction
Mart, Thanks for the help and disclaims
Edited by Valentim (2010-01-05 02:37 PM)
_________________________
|
Top
|
|
|
|
#197292 - 2010-01-06 12:43 PM
Re: Adding Printers separating groups
[Re: Valentim]
|
BradV
Seasoned Scripter
Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
|
Hi Roberto,
I'm confused. What does this do?$GrpArray = split(readprofilestring($file, '', ''), chr(10))
It's not going to read anything. Are you trying not to code each group into the script itself? If so, create another ini that just lists your groups and read it from there.
|
Top
|
|
|
|
#197295 - 2010-01-06 01:06 PM
Re: Adding Printers separating groups
[Re: BradV]
|
Valentim
Fresh Scripter
Registered: 2010-01-04
Posts: 46
Loc: Brazil, PE, Recife
|
Hello BradV,
This line will capture all the groups of the ini file, for example:
[Group01]
Printer=Print-Group01,Print-Group02
Default=Print-Group01
[Group02]
Printer=Print-Group02
Default=Print-Group02
[Group03]
Printer=Print-Group03,Print-Group01
Default=Print-Group03
the variable $ GrpArray will be an array with the values "Group01" "Group02" and "Group03"
The line which has
$GrpChave = split(readprofilestring($file, $Grupo, ''), chr(10)) the variable $GrpChave will also be an array with the values "Printer" and "Default"
the same thing will happen to the variable $Valores
$Valores = split(readprofilestring($file, $Grupo, $Chave), ",") The variable $Valores in the part of If $Valores ="Printer" and $Grupo ="Group01" will receive the following values Print-Group01 and Print-Group02
the part of If $Valores ="Default" and $Grupo ="Group01" will receive the following values Print-Group01
I hope you have understood what I tried to explain
_________________________
|
Top
|
|
|
|
#197308 - 2010-01-07 02:08 PM
Re: Adding Printers separating groups
[Re: Valentim]
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Try this little script to sanity check the groups:
$=SetOption("Explicit","ON")
Break ON
Dim $sGroup,$iIndex
$iIndex=0
"--Starting enumeration for "+@USERID+@CRLF
$sGroup=EnumGroup($iIndex)
While $sGroup
IIf(InGroup($sGroup)," Passed","**FAILED")+" checking InGroup() for '"+$sGroup+"'"+@CRLF
$iIndex=$iIndex+1 $sGroup=EnumGroup($iIndex)
Loop
"--Enumeration done"+@CRLF
|
Top
|
|
|
|
#197312 - 2010-01-07 03:00 PM
Re: Adding Printers separating groups
[Re: Richard H.]
|
Valentim
Fresh Scripter
Registered: 2010-01-04
Posts: 46
Loc: Brazil, PE, Recife
|
Your group names actually contain the word "group"?? (as in "Group Support" and not a group called "Support"). If InGroup('name')
'Is in the group' ?
Else
'is NOT in the group' ?
EndIf Glenn Yes, some groups have the word "group" at the beginning
Try this little script to sanity check the groups: $=SetOption("Explicit","ON")
Break ON
Dim $sGroup,$iIndex
$iIndex=0
"--Starting enumeration for "+@USERID+@CRLF
$sGroup=EnumGroup($iIndex)
While $sGroup
IIf(InGroup($sGroup)," Passed","**FAILED")+" checking InGroup() for '"+$sGroup+"'"+@CRLF
$iIndex=$iIndex+1 $sGroup=EnumGroup($iIndex)
Loop
"--Enumeration done"+@CRLF Not showing all groups that the User has the active directory
Edited by Valentim (2010-01-07 03:02 PM)
_________________________
|
Top
|
|
|
|
#197326 - 2010-01-08 11:52 AM
Re: Adding Printers separating groups
[Re: Richard H.]
|
Valentim
Fresh Scripter
Registered: 2010-01-04
Posts: 46
Loc: Brazil, PE, Recife
|
I found out what the problem was already resolved and the network administrator has placed the group as "local" and not the Network group, which is why the groups were not being display in the script of Richard.
Thanks for everyone's help, the script is working perfectly now.
Ini File:
[DOMAIN\Print DEMAN]
Printers=\\Server01\HP-2015-Deman
Default=\\Server01\HP-2015-Deman
[DOMAIN\Print SMAQF1]
Printers=\\Server01\HP-1320-SMAQF1
Default=\\Server01\HP-1320-SMAQF1
[DOMAIN\Print SMAQF2]
Printers=\\Server01\HP-2015-SMAQF2
Default=\\Server01\HP-2015-SMAQF2
[DOMAIN\Print UGB02]
Printers=\\Server01\HP-2015-UGB02
Default=\\Server01\HP-2015-UGB02
Script:
Break ON
CLS
; Altera o Titulo da Janela do MS-DOS
SetTitle ("Nome da Empresa [KiXtart @Kix]")
;================================================================
;= Função : DelPrinterConnections
;= Autor : Lonkero
;= UDF Site : http://www.kixtart.org/UDF/UDF_lister.php?what=post&code=83797
;= Contribuintes : Nenhum
;= Changes : Roberto Valentim
;= Descrição : Deleta todas as impressoas que foram adicionadas
;= apartir do servidor informado pelo parametro
;= $Server que devera ser informado.
;= Sintaxe : DelPrinterConnections($Server)
;= Parâmetros : $Server
;= Nome do Servidor
;= Retorna : Nada
;= Dependências : Nenhuma
;= Exemplo(s) : DelPrinterConnections("Servidor01")
;================================================================
Function DelPrinterConnections($Server)
;================================================================
DIM $c, $bk, $conn, $Index, $KeyName[5], $element
$c = 0
$bk = "HKEY_CURRENT_USER\Printers\Connections"
For $Index = 0 to 5
$KeyName[$Index] = EnumKey($bk, $Index)
Next
For Each $element in $KeyName
$conn = enumkey($bk,$c)
If (SubStr($element,3,12) = $Server) = 0
$c= $c + 1
$conn= delkey($bk + "\" + $conn)
$conn= enumkey($bk,$c)
EndIf
Next
EndFunction
;================================================================
;= Função : ENumGroupIni
;= Autor : Kent Dyer
;= UDF Site : http://www.kixtart.org/UDF/UDF_lister.php?what=post&code=84431
;= Contribuintes : Jens Meyer
;= Howard Bullock
;= Changes : Roberto Valentim
;= Descrição : Numera todos os grupos que estão no arquivo ini
;= que deverá ser informado pelo parametro $file
;= e o servidor no qual o grupo faz parte pelo
;= pelo parametro $Server.
;= Sintaxe : ENumGroupIni($file)
;= Parâmetros : $file
;= Arquivo para ser lido e usado
;= Retorna : Nada
;= Dependências : Nenhuma
;= Exemplo(s) : ENumGroupIni("C:\print.ini")
;================================================================
Function ENumGroupIni($file)
;================================================================
DIM $GrpArray, $Grupo, $GrpChave, $Chave, $Valores, $Valor
$GrpArray = split(readprofilestring($file, "", ""), chr(10))
For Each $Grupo in $GrpArray
If ($Grupo <> "")
If InGroup("$Grupo") = 0
$InGroups = $InGroups + "$Grupo"
$GrpChave = split(readprofilestring($file, $Grupo, ""), chr(10))
For Each $Chave in $GrpChave
If ($Chave = "Printers")
$Valores = split(readprofilestring($file, $Grupo, $Chave), ",")
For Each $Valor in $Valores
AddPrinterConnection("$Valor)
Next
EndIf
If ($Chave = "Default")
$Valores = split(readprofilestring($file, $Grupo, $Chave), ",")
For Each $Valor in $Valores
SetDefaultPrinter("$Valor)
Next
EndIf
Next
Else
EndIf
EndIf
Next
EndFunction
DelPrinterConnections("Server01")
ENumGroupIni("print.ini")
Edited by Valentim (2010-01-08 11:55 AM)
_________________________
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 262 anonymous users online.
|
|
|