#173503 - 2007-02-01 03:53 PM
Wildcards in registry?
|
JohnnyBoy
Fresh Scripter
Registered: 2007-02-01
Posts: 9
|
Hi, We are changing printservers. And lets say the old servers name is "oldserver" and the new "newserver"
Im trying to build a script that adds specific printers by different groups in AD. That is not a problem and it is solved. The problem is to delete all printers from oldserver.
To delete one specific printer i use :
If ingroup("Floor3")
$ReturnCode = KeyExist("HKEY_CURRENT_USER\Printers\Connections\,,oldserver,Hp_laserjet") If $ReturnCode = 1 ? "If Hp_laserjet exists it will be deleted" If delPrinterConnection ("\\oldserver\Hp_laserjet") = 1 ? "Removed printer Hp_laserjet" Endif Endif Endif
But what i want to do is to delete all printers added on "oldserver" Can I in some way use wildcard?
Please help!
|
|
Top
|
|
|
|
#173505 - 2007-02-01 04:09 PM
Re: Wildcards in registry?
[Re: Witto]
|
JohnnyBoy
Fresh Scripter
Registered: 2007-02-01
Posts: 9
|
Im still searching but I cant find it =( Please tell me how och a link to the old thread.... Thanks!
|
|
Top
|
|
|
|
#173508 - 2007-02-01 04:28 PM
Re: Wildcards in registry?
[Re: Witto]
|
JohnnyBoy
Fresh Scripter
Registered: 2007-02-01
Posts: 9
|
Im a too-much-newbie to kix to get this to work. The exaples are great but a bit too complex for me. The only thing i want is to delete all added printers from "oldserver". Not add new ones or so. Just the code to delete the old ones without having the specified printername.
Help ......
|
|
Top
|
|
|
|
#173510 - 2007-02-01 04:41 PM
Re: Wildcards in registry?
[Re: JohnnyBoy]
|
JohnnyBoy
Fresh Scripter
Registered: 2007-02-01
Posts: 9
|
Now im trying something like this, but i wont work. Im I close?
$key = "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts"
$i = 0
$printer = enumvalue($key, $i)
$server = split($printer,"\")[2] $prtname = split($printer,"\") [3] if $server ?"**************************************" ?"server is $server for printer $prtname" ?"**************************************" endif ;fix the connections if $server = "oldserver" DELPRINTERCONNECTION("$printer") ?"removed old printer-connection"
endif
|
|
Top
|
|
|
|
#173511 - 2007-02-01 04:52 PM
Re: Wildcards in registry?
[Re: JohnnyBoy]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
I liked your first script. Just loop through all the keys referring to an added printer on the workstation in the user profile.
If NOT @LOGONMODE
Break On
Else
Break Off
EndIf
Dim $RC
$RC=SetOption("Explicit", "On")
$RC=SetOption("NoMacrosInStrings", "On")
$RC=SetOption("NoVarsInStrings", "On")
$RC=SetOption("WrapAtEOL", "On")
Dim $Ptr, $index
$index = 0
$Ptr = EnumKey("HKCU\Printers\Connections\",$index)
While NOT @ERROR
"Printer with index " + $index + ": " + $Ptr ?
$index = $index + 1
$Ptr = EnumKey("HKCU\Printers\Connections\",$index)
Loop
|
|
Top
|
|
|
|
#173514 - 2007-02-01 05:25 PM
Re: Wildcards in registry?
[Re: Witto]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
Here, you can delete the keys. Be sure you do not want to replace them like in the old thread. Delete is forever.
If NOT @LOGONMODE
Break On
Else
Break Off
EndIf
Dim $RC
$RC=SetOption("Explicit", "On")
$RC=SetOption("NoMacrosInStrings", "On")
$RC=SetOption("NoVarsInStrings", "On")
$RC=SetOption("WrapAtEOL", "On")
Dim $Ptr, $index, $OldServer
$index = 0
$OldServer = "OldServer"
$Ptr = EnumKey("HKCU\Printers\Connections\",$index)
While NOT @ERROR
;"Printer with index " + $index + ": " + $Ptr ?
If InStr($Ptr,$OldServer)
;"KeyName to delete: " + "HKCU\Printers\Connections\" + $Ptr + "\" ?
$RC = DelKey("HKCU\Printers\Connections\" + $Ptr + "\")
EndIf
$index = $index + 1
$Ptr = EnumKey("HKCU\Printers\Connections\",$index)
Loop
|
|
Top
|
|
|
|
#173520 - 2007-02-01 09:30 PM
Re: Wildcards in registry?
[Re: Witto]
|
JohnnyBoy
Fresh Scripter
Registered: 2007-02-01
Posts: 9
|
Thank you very much!! That is exactly what I wanted. Many thanks mighty Witto.
|
|
Top
|
|
|
|
#173522 - 2007-02-01 09:44 PM
Re: Wildcards in registry?
[Re: JohnnyBoy]
|
JohnnyBoy
Fresh Scripter
Registered: 2007-02-01
Posts: 9
|
Witto : hmmz .... it only deletes one printer. If i run it again it deletes the second... and so on. But isnīt it already looped in the code you posted?
|
|
Top
|
|
|
|
#173526 - 2007-02-01 10:29 PM
Re: Wildcards in registry?
[Re: JohnnyBoy]
|
JohnnyBoy
Fresh Scripter
Registered: 2007-02-01
Posts: 9
|
hmmz. I added 8 printers from the old server. First run the script deleted 4 printers. Second run i deleted 2 printers. And third run the other 2.
Is that strange!? =)
|
|
Top
|
|
|
|
#173534 - 2007-02-02 01:03 AM
Re: Wildcards in registry?
[Re: JohnnyBoy]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
I see. I think because I first take index 0 and delete that one. Then everything shifts one up... Maybe enumerate first to get the highest index and then count back to 0.
If NOT @LOGONMODE
Break On
Else
Break Off
EndIf
Dim $RC
$RC=SetOption("Explicit", "On")
$RC=SetOption("NoMacrosInStrings", "On")
$RC=SetOption("NoVarsInStrings", "On")
$RC=SetOption("WrapAtEOL", "On")
Dim $Ptr, $index, $OldServer
$index = 0
$OldServer = "OldServer"
$Ptr = EnumKey("HKCU\Printers\Connections\",$index)
While NOT @ERROR
;"Printer with index " + $index + ": " + $Ptr ?
$index = $index + 1
$Ptr = EnumKey("HKCU\Printers\Connections\",$index)
Loop
If 0 < $index
$index = $index - 1
Do
$Ptr = EnumKey("HKCU\Printers\Connections\",$index)
If InStr($Ptr,$OldServer)
;"KeyName to delete: " + "HKCU\Printers\Connections\" + $Ptr + "\" ?
$RC = DelKey("HKCU\Printers\Connections\" + $Ptr + "\")
EndIf
$index = $index - 1
Until 0 > $index
EndIf
|
|
Top
|
|
|
|
#173582 - 2007-02-03 10:54 AM
Re: Wildcards in registry?
[Re: Witto]
|
JohnnyBoy
Fresh Scripter
Registered: 2007-02-01
Posts: 9
|
Now it is really working! Thanks a bunch!! Really glad you offered the time to help me. And I probably be back =)
Edited by JohnnyBoy (2007-02-03 10:55 AM)
|
|
Top
|
|
|
|
#173634 - 2007-02-05 11:38 AM
Re: Wildcards in registry?
[Re: Richard H.]
|
Witto
MM club member
   
Registered: 2004-09-29
Posts: 1828
Loc: Belgium
|
No, only if the server is "OldServer", else add 1 to $index and evaluate the next key. But hey, thanks for the hint.
|
|
Top
|
|
|
|
#173648 - 2007-02-05 04:26 PM
Re: Wildcards in registry?
[Re: Witto]
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Ooops, my bad. I mis-read and thought you were deleting all records.
The alternative method is then not to increment the counter if you are deleting a record:
If NOT @LOGONMODE
Break On
Else
Break Off
EndIf
Dim $RC
$RC=SetOption("Explicit", "On")
$RC=SetOption("NoMacrosInStrings", "On")
$RC=SetOption("NoVarsInStrings", "On")
$RC=SetOption("WrapAtEOL", "On")
Dim $Ptr, $index, $OldServer
$index = 0
$OldServer = "OldServer"
$Ptr = EnumKey("HKCU\Printers\Connections\",$index)
While NOT @ERROR
If InStr($Ptr,$OldServer)
$RC = DelKey("HKCU\Printers\Connections\" + $Ptr + "\")
Else
$index = $index + 1
EndIf
$Ptr = EnumKey("HKCU\Printers\Connections\",$index)
Loop
|
|
Top
|
|
|
|
#173765 - 2007-02-08 08:40 AM
Re: Wildcards in registry?
[Re: Witto]
|
JohnnyBoy
Fresh Scripter
Registered: 2007-02-01
Posts: 9
|
Yep! Thanks everyone! My script is already implemented in our system.
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 2220 anonymous users online.
|
|
|