Page 2 of 2 <12
Topic Options
#189996 - 2008-10-02 04:25 PM Re: Improve speed in my script [Re: edjekroketje]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
Try this, see if it works faster:
 Code:
$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 Offline
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:

 Code:
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_ Moderator Offline
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:
 Code:
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 Offline
Fresh Scripter

Registered: 2008-09-19
Posts: 20
Loc: Amsterdam, the Netherlands
 Originally Posted By: BradV
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:

 Code:
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 Offline
Fresh Scripter

Registered: 2008-09-19
Posts: 20
Loc: Amsterdam, the Netherlands
 Originally Posted By: apronk
BradV is right, Although to keep the script more in the type of code you put it in, I'd put it like this:
 Code:
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 Offline
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
#190345 - 2008-10-28 02:31 PM Re: Improve speed in my script [Re: edjekroketje]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
That's good news. Thanks for the follow-up feedback.
Top
#190352 - 2008-10-28 06:06 PM Re: Improve speed in my script [Re: NTDOC]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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.
_________________________
!

download KiXnet

Top
#190373 - 2008-10-29 08:10 PM Re: Improve speed in my script [Re: edjekroketje]
Indigo Offline
Fresh Scripter
**

Registered: 2008-10-01
Posts: 34
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.

Top
#190393 - 2008-10-30 09:29 AM Re: Improve speed in my script [Re: Indigo]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Roaming profiles

But that is just a personal opinion. Had lots of issues with roaming profiles in the past so I avoid them like the plague nowadays.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#190415 - 2008-10-30 09:49 PM Re: Improve speed in my script [Re: Mart]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
me too.
_________________________
!

download KiXnet

Top
#190513 - 2008-11-05 09:14 PM Re: Improve speed in my script [Re: Lonkero]
MattColeman Offline
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
#190515 - 2008-11-05 10:47 PM Re: Improve speed in my script [Re: MattColeman]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
easier?
well, the original doesn't even work, so quess it would be easier to write a working version ;\)
_________________________
!

download KiXnet

Top
#193838 - 2009-05-14 11:54 AM Re: Improve speed in my script [Re: Lonkero]
edjekroketje Offline
Fresh Scripter

Registered: 2008-09-19
Posts: 20
Loc: Amsterdam, the Netherlands
 Originally Posted By: Lonkero
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 Offline
Fresh Scripter

Registered: 2008-09-19
Posts: 20
Loc: Amsterdam, the Netherlands
 Originally Posted By: Indigo
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 Offline
Fresh Scripter

Registered: 2008-09-19
Posts: 20
Loc: Amsterdam, the Netherlands
 Originally Posted By: MattColeman
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
Page 2 of 2 <12


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 507 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.068 seconds in which 0.024 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org