#189996 - 2008-10-02 04:25 PM
Re: Improve speed in my script
[Re: edjekroketje]
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
|
Try this, see if it works faster:
$WSHNetwork = CreateObject("WScript.Network")
$WSHPrinters = $WSHNetwork.EnumPrinterConnections
For $i=0 To WSHPrinters.Count -1
If Left($WSHPrinters.Item($i),2) = "\\"
$WSHNetwork.RemovePrinterConnection($WSHPrinter.Items($i),1,1)
EndIf
Next
|
Top
|
|
|
|
#190010 - 2008-10-03 12:38 PM
Re: Improve speed in my script
[Re: edjekroketje]
|
BradV
Seasoned Scripter
Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
|
I think you are missing an assignment. You check Keyexist, but don't store it's value anywhere and then in the next line assume the value is in the variable, $returncode. Try:
IF INGROUP ("P_printer_###_***")
$Returncode = KeyExist("HKEY_CURRENT_USER\Printers\Connections\,,AS-01,printer_###_***\")
if $Returncode = 0
ADDPRINTERCONNECTION("\\$ASERVER\printer_###_blanco") ? "printer_###_*** nieuw geinstalleerd"
endif
else
$Returncode = Keyexist ("HKEY_CURRENT_USER\Printers\Connections\,,AS-01,printer_###_***\")
if $Returncode = 1
DELPRINTERCONNECTION("\\$ASERVER\printer_###_blanco") ? "printer_###_*** verwijderd"
endif
endif
|
Top
|
|
|
|
#190012 - 2008-10-03 02:46 PM
Re: Improve speed in my script
[Re: BradV]
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
|
BradV is right, Although to keep the script more in the type of code you put it in, I'd put it like this:
If InGroup("P_printer_###_***")
If KeyExist("HKCU\Printers\Connections\,,AS-01,printer_###_***\")
$=AddPrinterConnection("\\"+$ASERVER+"\printer_###_blanco")
? "printer_###_*** nieuw geinstalleerd"+"Error: "+@ERROR
EndIf
Else
If KeyExist("HKCU\Printers\Connections\,,AS-01,printer_###_***\")
$=DelPrinterConnection("\\"+$ASERVER+"\printer_###_blanco")
? "printer_###_*** verwijderd"+"Error: "+@ERROR
EndIf
EndIf
|
Top
|
|
|
|
#190030 - 2008-10-06 10:28 AM
Re: Improve speed in my script
[Re: BradV]
|
edjekroketje
Fresh Scripter
Registered: 2008-09-19
Posts: 20
Loc: Amsterdam, the Netherlands
|
I think you are missing an assignment. You check Keyexist, but don't store it's value anywhere and then in the next line assume the value is in the variable, $returncode. Try: IF INGROUP ("P_printer_###_***")
$Returncode = KeyExist("HKEY_CURRENT_USER\Printers\Connections\,,AS-01,printer_###_***\")
if $Returncode = 0
ADDPRINTERCONNECTION("\\$ASERVER\printer_###_blanco") ? "printer_###_*** nieuw geinstalleerd"
endif
else
$Returncode = Keyexist ("HKEY_CURRENT_USER\Printers\Connections\,,AS-01,printer_###_***\")
if $Returncode = 1
DELPRINTERCONNECTION("\\$ASERVER\printer_###_blanco") ? "printer_###_*** verwijderd"
endif
endif
You are absolutely right! I have to do the assignment...
_________________________
Still thinking about a good signature
|
Top
|
|
|
|
#190031 - 2008-10-06 10:32 AM
Re: Improve speed in my script
[Re: Arend_]
|
edjekroketje
Fresh Scripter
Registered: 2008-09-19
Posts: 20
Loc: Amsterdam, the Netherlands
|
BradV is right, Although to keep the script more in the type of code you put it in, I'd put it like this:
If InGroup("P_printer_###_***")
If KeyExist("HKCU\Printers\Connections\,,AS-01,printer_###_***\")
$=AddPrinterConnection("\\"+$ASERVER+"\printer_###_blanco")
? "printer_###_*** nieuw geinstalleerd"+"Error: "+@ERROR
EndIf
Else
If KeyExist("HKCU\Printers\Connections\,,AS-01,printer_###_***\")
$=DelPrinterConnection("\\"+$ASERVER+"\printer_###_blanco")
? "printer_###_*** verwijderd"+"Error: "+@ERROR
EndIf
EndIf
Many thanks to Bradv and Apronk. I will put Apronk's suggestions in and let you know how things turn out!
Edited by edjekroketje (2008-10-06 10:43 AM) Edit Reason: spelling!
_________________________
Still thinking about a good signature
|
Top
|
|
|
|
#190342 - 2008-10-28 08:41 AM
Re: Improve speed in my script
[Re: edjekroketje]
|
edjekroketje
Fresh Scripter
Registered: 2008-09-19
Posts: 20
Loc: Amsterdam, the Netherlands
|
Well, it's working! All of the script is normally running in under a second. That is of course when no printers need to be installed or removed. Even then however, all the work is done within 10 seconds wich is a great improvement compared to what it was before (around 50 seconds)
Solved!
_________________________
Still thinking about a good signature
|
Top
|
|
|
|
#190513 - 2008-11-05 09:14 PM
Re: Improve speed in my script
[Re: Lonkero]
|
MattColeman
Fresh Scripter
Registered: 2008-05-19
Posts: 12
Loc: Kitchener-Waterloo, ON
|
KeyExist("HKEY_CURRENT_USER\Printers\Connections\,,AS-01,printer_###_***\") if $Returncode = 0 ADDPRINTERCONNECTION("\\$ASERVER\printer_###_blanco") ? "printer_###_*** nieuw geinstalleerd" endif else
There's an easier way to write this:
if keyexist("registrykey")=0 dostuff endif
just my 2 cent's worth..
|
Top
|
|
|
|
#193838 - 2009-05-14 11:54 AM
Re: Improve speed in my script
[Re: Lonkero]
|
edjekroketje
Fresh Scripter
Registered: 2008-09-19
Posts: 20
Loc: Amsterdam, the Netherlands
|
reduction to one fifth of what it used to be, that's already something.
but was the improvement only because of the printer code enhancements?
me just curious... as if so, you should have pretty slow network or server responding darn slowly.
Strange enough improvement came from not disconnecting a printer that was'nt ven connected in the first place. In the present we look for a printer connection. If that is not there, why bother trying to disconnect the thing?
_________________________
Still thinking about a good signature
|
Top
|
|
|
|
#193839 - 2009-05-14 11:54 AM
Re: Improve speed in my script
[Re: Indigo]
|
edjekroketje
Fresh Scripter
Registered: 2008-09-19
Posts: 20
Loc: Amsterdam, the Netherlands
|
are you using roaming profiles?
If so you can be assured that if you remove the printer connections .. they will remain even if you don't map them every single time.
We used to map the pritners every time the computer booted at logon time. Toook for freeking ever.. well i removed the printer mappings and because we have roaming profiles the printers were already saved, so i don't have to worry about mapping them. Its been 6+ months now, and we still havn't had to run the printer mapping portion of our script.
Also .. even if you re-load the system it will still remember the printers that were originally mapped because its in the roaming profile.
anyway hope this helps.
No, we are not using romaing profiles, but we like to change printer connections when a user starts using a different printer. For instance when he or she moves to a different location in the office and another printer is closer by.
Edited by edjekroketje (2009-05-14 11:59 AM)
_________________________
Still thinking about a good signature
|
Top
|
|
|
|
#193840 - 2009-05-14 11:59 AM
Re: Improve speed in my script
[Re: MattColeman]
|
edjekroketje
Fresh Scripter
Registered: 2008-09-19
Posts: 20
Loc: Amsterdam, the Netherlands
|
KeyExist("HKEY_CURRENT_USER\Printers\Connections\,,AS-01,printer_###_***\") if $Returncode = 0 ADDPRINTERCONNECTION("\\$ASERVER\printer_###_blanco") ? "printer_###_*** nieuw geinstalleerd" endif else
There's an easier way to write this:
if keyexist("registrykey")=0 dostuff endif
just my 2 cent's worth..
Yep you're right
_________________________
Still thinking about a good signature
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 507 anonymous users online.
|
|
|