Sign in to follow this  
Followers 0
MAC2979

"Looping"

6 posts in this topic

I have to write a script that will append a value into the registery for each entry under a set key. The number of entires can vary from system to system it can be as little as 2 or as many as 50.

Is there some way to loop through a key like this?

Example:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}

\0000\Speed

\0001\Speed

\0002\Speed

....

\00??\Speed

Share this post


Link to post
Share on other sites



Look at RegEnumKey and RegEnumVal, either or both should do what you're looking to do.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

BrewManNH, the problem I see with this (steming from looking at the examples mostly) is the FOR loop has a set end, I can't use something like

For $I = 1 to 10

I don't know what the vaule of "10" will be for every machine, all I know is that each system will have at least 1 entry but so far I've seen as many as 25 (but I've only checked a few systems and I have over 14,000).

I'm wondering if I can use Autoit to do something like..

While not end of "KeyName" Do

Write something to ever Key under

End While

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Just use something like this...its not perfect but it works.

For $i = 1 to 100

$rtn = RegEnumKey ("keyname", $i)

If @error = -1 Then ExitLoop

;Do what you want to do with it.

Next

Edited by LurchMan

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

how about:

$iCounter = 1
While True
   RegEnumKey ("test",$iCounter)
   If @error ExitLoop
   $iCounter+=1
WEnd
Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I have to write a script that will append a value into the registery for each entry under a set key. The number of entires can vary from system to system it can be as little as 2 or as many as 50.

Is there some way to loop through a key like this?

Example:

HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlClass{4D36E972-E325-11CE-BFC1-08002bE10318}

0000Speed

0001Speed

0002Speed

....

00??Speed

This should get you what you want.

$i = 1
While 1
$n = $i - 1
$aKey = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}"
$var = RegEnumKey($aKey, $i)
If @error <> 0 then ExitLoop
If Not StringInStr($var, $n) then ContinueLoop ;Only process keys that have numbers in them e.g. 0000, 0001 etc
MsgBox(4096, "SubKey #" & $i & " under HKLM\Software: ", $aKey & "\" & $var & "\Speed") ; Do something here.. e.g. RegWrite a value
$i = $i + 1
WEnd
Edited by EndFunc

EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0