Jlmartinez
(Getting the hang of it)
2008-09-16 01:13 PM
more speed?

How can I increase the speed of my script? Is there any way to optimize it?

Glenn BarnasAdministrator
(KiX Supporter)
2008-09-16 01:27 PM
Re: more speed?

Post a copy and we'll take a look!

There are several optimization methods available through alternate logic, or even different commands or UDFs.

Glenn


LonkeroAdministrator
(KiX Master Guru)
2008-09-16 01:55 PM
Re: more speed?

Glenn is right, there are huge amounts of optimizations to be done but they all depend on the script and without knowing anything about it, it's darn hard to help...

BradV
(Seasoned Scripter)
2008-09-16 02:16 PM
Re: more speed?

A suggestion before you make any changes, put @time at the beginning and end of your script and re-direct to a log. That way as you make changes, you can have empirical evidence of any improvements.

Glenn BarnasAdministrator
(KiX Supporter)
2008-09-17 01:02 AM
Re: more speed?

Actually, I like
$STime = @TICKS

your code...

$TTime = cdbl(@TICKS - $STime) / 1000.0
'Total time to run: ' $TTime ' seconds.' ?

which shows time in thousands of a second.

Glenn


Jlmartinez
(Getting the hang of it)
2008-09-17 09:09 AM
Re: more speed?

I have a kix with many:

"If InGroup("GG-DPT-technic")

;----AGREGAMOS LAS IMPRESORAS DEL SERVICIO----
SHELL "regedit.exe /s "+$ruta+"imp-2-I10010.reg"
SHELL "regedit.exe /s "+$ruta+"imp-2-I10008.reg"
SHELL "regedit.exe /s "+$ruta+"imp-1-0AG05.reg"
SHELL "regedit.exe /s "+$ruta+"imp-2-I10012.reg"
"

Can I replace the shell with something else? addprinter something like?


Mart
(KiX Supporter)
2008-09-17 09:13 AM
Re: more speed?

You could use the WriteValue() function. It depends a bit on how big the reg imports are if this will save you some time.

Glenn BarnasAdministrator
(KiX Supporter)
2008-09-17 12:55 PM
Re: more speed?

While the size of the .reg files can impact speed to some degree, realize that every time you Shell, you start up a new environment, possibly wait for CMD.exe to load and initialize, load and run the command, process the data, etc... The point is, there's significant overhead processing Shell commands instead of using built-in commands and functions.

If your reg files are managing printers, native commands would likely be much faster. If they are generic registry data, Kix has a WriteValue command for single value writes, and LoadHive and LoadKey to natively load registry data from a file.

Glenn


Arend_
(MM club member)
2008-09-17 01:51 PM
Re: more speed?

Besides the good suggestions given, check for one reg setting (ReadValue) if it's set before you import regs, or even use WriteValue. That should save some time.

Jlmartinez
(Getting the hang of it)
2008-09-17 01:52 PM
Re: more speed?

my files are managing printer, add printers. How can I use native commands?

Arend_
(MM club member)
2008-09-17 02:00 PM
Re: more speed?

Show us the current script, we can give you advice and/or code suggestions. Besides that look in the KiX documentation (download the kix 4.60 package from the main site) and look at the laundrylist of native commands such as AddPrinterConnection and SetDefaultPrinter.

Mart
(KiX Supporter)
2008-09-17 02:01 PM
Re: more speed?

Kix has the AddPrinterConnection, SetDefaultprinter and DelPrinterConnection functions that you can use to add, set as default and remove printers. How to use them is explained on pages 51/52, 60 and 95/96 of the 4.60 manual that comes with every download.

Any other registry settings for your printers can be done with for example the WriteValue function like Glenn suggested.


Jlmartinez
(Getting the hang of it)
2008-09-17 02:09 PM
Re: more speed?

If InGroup("GG-DPT-AULAFORMACION")
SHELL "regedit.exe /s "+$rute+"imp-2-I01101.reg"
EndIf

If InGroup("-DG-Agriculture")
SHELL "regedit.exe /s "+$rute+"imp-2-I13104.reg"
SHELL "regedit.exe /s "+$rute+"imp-2-I13005.reg"
SHELL "regedit.exe /s "+$rute+"imp-2-I13101.reg"
EndIf

This is a part. This is repeated for groups very much, around 50. What would be a more optimal way.All this is to add printers to register in HKCU\Printers\connections. Thanks


Mart
(KiX Supporter)
2008-09-17 02:13 PM
Re: more speed?

AddPrinterConnection will do just fine to add printers and SetdefaultPrinter will set the default printer you need.

ChristopheM
(Hey THIS is FUN)
2008-09-17 04:30 PM
Re: more speed?

Hi,

if all .reg files are independent, you could start regedit with RUN instead of SHELL.

Printers will be added in background but your script kix continues !!!


BradV
(Seasoned Scripter)
2008-09-17 04:55 PM
Re: more speed?

I would question if you really need to write to the registry at every log in. How about reading from the registry to see if the value exists? If not, then write.

LonkeroAdministrator
(KiX Master Guru)
2008-09-17 11:01 PM
Re: more speed?

yes, if that is printer script, just do:
if not primapstate("\\myserver\myprinter")
; do the printer stuff
endif

that should be as fast as it can be...


Jlmartinez
(Getting the hang of it)
2008-09-18 08:43 AM
Re: more speed?

"you really need to write to the registry at every log in??"


Only when I add a new printer to print server, but that's not something I would control.


edjekroketje
(Fresh Scripter)
2008-09-19 11:51 AM
Re: more speed?

This is an interesting topic. Since we can do with a speed improvement in our script ourselves, i have opened a similar topic myself. Will try to help here. I can see that the addprinter command works fine. Also the delprinter to disconnect printers if not neccasary. I'm wondering if that will work with wildcards as well?


Mart
(KiX Supporter)
2008-09-19 12:15 PM
Re: more speed?

Ed,

Posting your issue (although similar to the original poster’s issue) in someone else’s thread is considered hijacking and is not approved by the other members on this board and certainly not by the mods and admins because it puts the focus of the thread on your issue and not the one the original poster had.
Please start your own thread and (if needed) include a link to this thread.

Ok, all that being said I see lots of ways to improve on your script. Remove the goto’s, remove the use of bat(ch) files, etc….


[edit]
BTW: Welcome to the board \:\)
[/edit]


edjekroketje
(Fresh Scripter)
2008-09-19 03:47 PM
Re: more speed?

Mart,

Sorry about the hijack, it was not my intention to set the focus away from JLmartinez' problem.
Will open my own topic, and start work on improving my script. It really needs improvement!

Well, i'll go right ahead and open my own topic here. In the meanwhile i'll try and contribute to this one.

Thanks for the welcome!

Ed