Jump to content

More then 10 Regwrite


 Share

Recommended Posts

Hi how to know more then 20 Regwrite were successfully written in machine like regwrite return to 1 when get successful

$reg1  = RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Test", "TestKey", "REG_SZ", "Hello this is a test")
if reg1 = 1 then 
MsgBox(64, "regwrite", "Reg successful")
endif

but how to manage more 10 regkeys ? dont want to give vars to all regwrite any faster and better way

Regards

Sim

Link to comment
Share on other sites

i think this would be fine wat u say about ? my question

Is it checking all regwrite error or only last regwrite error

RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Test", "TestKey1", "REG_SZ", "Hello this is a test")
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Test", "TestKey2", "REG_SZ", "Hello this is a test")
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Test", "TestKey3", "REG_SZ", "Hello this is a test")
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Test", "TestKey4", "REG_SZ", "Hello this is a test")
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Test", "TestKey5", "REG_SZ", "Hello this is a test")
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Test", "TestKey6", "REG_SZ", "Hello this is a test")
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Test", "TestKey7", "REG_SZ", "Hello this is a test")
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Test", "TestKey8", "REG_SZ", "Hello this is a test")
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Test", "TestKey9", "REG_SZ", "Hello this is a test")
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Test", "TestKey10", "REG_SZ", "Hello this is a test")
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Test", "TestKey11", "REG_SZ", "Hello this is a test")

if @error then 
    MsgBox(64 , @error , @error)
Else
        MsgBox(64 , "No error!" , "No error!")
    EndIf
Edited by autoitxp
Link to comment
Share on other sites

This is a quicker way, just replace the array data with your real value names and your real data:

Dim $myRegValueArray[25] = ["valueName01", "valueName02", "valueName03", "valueName04", "valueName05", "valueName06", "valueName07", "valueName08", "valueName09", "valueName10"]
Dim $myRegDataArray[25] = ["data01", "data02", "data03", "data04", "data05", "data06", "data07", "data08", "data09", "data10"]
For $i = 1 To 10 
    $returnValue  = RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Test", $myRegValueArray[$i], "REG_SZ", $myRegDataArray[$i])
    If Not $returnValue Then
        MsgBox(64, "regwrite", "Reg successful")
    EndIf
Next
; If there is no error, no message box is shown.

It might be better to write errors to a log file than to use MsgBox - look in the AutoIt Help file for this, it is under User Defined Functions > File Management:

#include <File.au3>

_FileWriteLog ( $sLogPath, $sLogMsg )

Edited by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

Here is a slight improvement on the code in my last post. It tries to do all the writing first, then tells you if there was any error:

Global $ThereWasAnError = 0
Dim $myRegValueArray[25] = ["valueName01", "valueName02", "valueName03", "valueName04", "valueName05", "valueName06", "valueName07", "valueName08", "valueName09", "valueName10"]
Dim $myRegDataArray[25] = ["data01", "data02", "data03", "data04", "data05", "data06", "data07", "data08", "data09", "data10"]
For $i = 1 To 10 
    $returnValue  = RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Test", $myRegValueArray[$i], "REG_SZ", $myRegDataArray[$i])
    If Not $returnValue Then
        $ThereWasAnError = 1
    EndIf
Next
If $ThereWasAnError Then
    MsgBox(64, "TestWare - Error", "There was an error writing to the registry.")
EndIf
; If there is no error, no message box is shown.

I learned here on the AutoIt forum that they call this method "iterating through an array"

Edited by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

Thanks alot

:D

Global $ThereWasAnError = 0

$regpath = "HKEY_LOCAL_MACHINE\SOFTWARE\test"
$sregpath = "HKEY_LOCAL_MACHINE\SOFTWARE\test\Default"

Dim $myRegpathArray[25]  = [$regpath, $regpath, $regpath, $regpath, $regpath, $regpath, $regpath, $regpath, $regpath,  $regpath , $sregpath , $sregpath ,$sregpath]
Dim $myRegtypeArray[25]  = ["REG_DWORD", "REG_DWORD", "REG_DWORD", "REG_DWORD", "REG_DWORD", "REG_DWORD", "REG_DWORD", "REG_DWORD", "REG_DWORD", "REG_BINARY" , "REG_DWORD" ,"REG_DWORD" ,"REG_DWORD"]
Dim $myRegValueArray[25] = ["AllowLoopback", "MSLogonRequired", "NewMSLogon", "UseDSMPlugin", "ConnectPriority", "DebugLevel", "DebugMode", "DisableTrayIcon", "LoopbackOnly" , "DSMPlugin" , "AllowEditClients", "AllowProperties" , "AllowShutdown" ]
Dim $myRegDataArray[25]  = ["1", "1", "1", "1", "0", "0", "0", "0", "0", "000000000000000000000000" , "1" ,"1" ,"1"]
For $i = 1 To 13 
    $returnValue  = RegWrite($myRegpathArray[$i], $myRegValueArray[$i], $myRegtypeArray[$i] , $myRegDataArray[$i])
    If Not $returnValue Then
        $ThereWasAnError = 1
    EndIf
Next
If $ThereWasAnError Then
    MsgBox(64, "TestWare - Error", "There was an error writing to the registry.")
EndIf
Edited by autoitxp
Link to comment
Share on other sites

  • 7 years later...

Sry for reply on this old Thread, but it's a good example :D

This is for what i need...

Global $result = StringLeft(@ScriptDir, 2)

Global $userINI[4]
$userINI[0] = $result & "\user1.ini"
$userINI[1] = $result & "\user2.ini"
$userINI[2] = $result & "\user3.ini"
$userINI[3] = $result & "\user4.ini"

Func _registry()

$sVar = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Test\Recent File List", "File1") ;Read a Value if exist
Global $test = StringLeft($sVar, 2) ;Extract Driveletter from Value if exist

Global $ThereWasAnError = 0

$path2 = "HKEY_LOCAL_MACHINE\SOFTWARE\Test\Recent File List"
$path3 = "HKEY_LOCAL_MACHINE\SOFTWARE\Test\Settings"

Dim $myRegpathArray[25]  = [$path2, $path2, $path2, $path2, $path2, $path3, $path3, $path3, $path3, $path3]
Dim $myRegtypeArray[25]  = ["REG_SZ", "REG_SZ", "REG_SZ", "REG_SZ", "REG_SZ", "REG_SZ", "REG_SZ", "REG_SZ", "REG_SZ", "REG_SZ"]
Dim $myRegValueArray[25] = ["", "File1", "File2", "File3", "File4", "", "File1", "File2", "File3", "File4"]
Dim $myRegDataArray[25]  = ["", $userini[0], $userini[1], $userini[2], $userini[3], "", $userini[0], $userini[1], $userini[2], $userini[3]]
For $i = 0 To 11
    $returnValue  = RegWrite($myRegpathArray[$i], $myRegValueArray[$i], $myRegtypeArray[$i] , $myRegDataArray[$i])
    If Not $returnValue Then
        $ThereWasAnError = 1
    EndIf
Next
If $ThereWasAnError Then
    MsgBox(64, "TestWare - Error", "There was an error writing to the registry.")
EndIf

EndFunc

It writes everything in registry, but still brings $ThereWasAnError error message on end - whats wrong?

Link to comment
Share on other sites

Sry for reply on this old Thread, but it's a good example :D

This is for what i need...

It writes everything in registry, but still brings $ThereWasAnError error message on end - whats wrong?

If Not $returnValue Then
        $ThereWasAnError = 1
        MsgBox(64, "TestWare - Error", "There was an error writing to the registry."&@CR&'at $i = '&$i&' where:'&@CR& _
        'RegWrite("'&$myRegpathArray[$i]&'", "'&$myRegValueArray[$i]&'", "'&$myRegtypeArray[$i]&'", "'&$myRegDataArray[$i]&'")' _
        )
    EndIf

...that way you have a better debug

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...