Jump to content

RegWrite & RegRead at "HKEY_LOCAL_MACHINE"


Recommended Posts

Hi

This piece of code creates and reads OK a key at  "HKEY_LOCAL_MACHINE" and can be changed for a key at "HKEY_CURRENT_USER"

$sta= RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor", "wav", "REG_SZ", "5555")
    MsgBox(4096,"wrote", $sta &@cr& @error)
    $zz= RegRead  ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor", "wav")
    MsgBox(4096,"readed","="&$zz &@cr& @error)
    Exit

With  HKEY_CURRENT_USER, in RegEdit we can see the created key, and we can create the key by hand/RegEdit and everything Works OK.

At  HKEY_LOCAL_MACHINE we can´t see the created key above  thru RegEdit, but it Works (even not seeing, I can read). But  if I create "by hand"/RegEdit  the key,  it can´t read it with   $zz= RegRead  ("HKEY_LOCAL_MACHINE.... above.

I´m the PC´s WIN.7 administrator. Even so I ran RegEdit as administrator and also the compiled AU3 and also plain. No changes.

edit: even if Try   "HKEY_LOCAL_MACHINE\SOFTWARE\AAA", "wav", the same holds true.

$sta= RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\AAA", "wav", "REG_SZ", "4444")
    MsgBox(4096,"wrote", $sta &@cr& @error)
    $zz= RegRead  ("HKEY_LOCAL_MACHINE\SOFTWARE\AAA", "wav")
    MsgBox(4096,"readed","="&$zz &@cr& @error)
    Exit

Seems that it creates this key at another place.... I can read the above value ("4444"), even after a boot, even the key not showing in regedit. And if I create it by hand key AAA/wav with a distinct value (666), t, it continues Reading the old value = 444.

Thanks

Jose

 

Edited by joseLB
Link to post
Share on other sites

Hi,

Is your Windows a x64-bit Windows? if that is the case your script creates and reads the value under x86 key and you won't be able to see the key under x64. The script will create the key and you will see it if you compile your script as x64-bit.

Edited by Factfinder
Link to post
Share on other sites

As @Factfinder mentioned:

Script compiled as 32-bit on a 64-bit Operating System

To access 32-Bit Hive - HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node use:
HKLM
To access 64-Bit Hive - HKEY_LOCAL_MACHINE use:
HKLM64

Script compiled as 64-bit on a 64-bit Operating System:

To access 32-Bit Hive - HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node use:
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node
To 64-Bit Hive - HKEY_LOCAL_MACHINE use:
HKEY_LOCAL_MACHINE

I normally use the following in my scripts:

Global $g_sHKLM32 = @AutoItX64 ? "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node" : "HKLM"
Global $g_sHKLM64 =  @AutoItX64 ? "HKEY_LOCAL_MACHINE" : "HKLM64"

Global $g_sProgramFilesDir32 = RegRead($g_sHKLM32 & "\SOFTWARE\Microsoft\Windows\CurrentVersion", "ProgramFilesDir")
ConsoleWrite("32-Bit Program Files Directory: " & $g_sProgramFilesDir32 & @CRLF)

Global $g_sProgramFilesDir64 = RegRead($g_sHKLM64 & "\SOFTWARE\Microsoft\Windows\CurrentVersion", "ProgramFilesDir")
ConsoleWrite("64-Bit Program Files Directory: " & $g_sProgramFilesDir64 & @CRLF)

 

Link to post
Share on other sites

factfinder/and Subz

Thank you really very much! I will try undestand all that, I could´nt imagine that withou your help.

I´m  using x32, and can´t compile in x64, due to some dlls I use, for example, rs232 serial one.

But if that is stable even under KLM as the example from Subz , it´s ok for me.

This script must work in win7 and win 10. Tomorrow I will try in a win10 system, but I think it will work there, correct?

Thanks again

Jose

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By VeeDub
      Hello,
      I am trying to use RegWrite to create a key within HKLM on W10 without success.
      I've had a look at a number of posts on the forum to troubleshoot, without success.
      This post seems highly relevant
      Here is my latest script with output
      ; Read/write data to registry #RequireAdmin Example() Func Example() Local $Status = "" ; Check if the registry key is already existing, so as not to damage the user's system. RegRead("HKLM\SOFTWARE\Microsoft\F1", "Key1") ConsoleWrite("Error: " & @error & @CRLF) ; Write a single REG_SZ value to the key "Key1". $Status = RegWrite("HKLM\SOFTWARE\Microsoft\F1", "Key1", "REG_SZ", "This is an example of RegWrite") ConsoleWrite("Status: " & $Status & @TAB & " Error: " & @error & @CRLF) EndFunc ;==>Example  
      Output
      >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "D:\Temp\Macrium\Registry_write_read.au3" /UserParams +>16:18:46 Starting AutoIt3Wrapper (21.316.1639.1) from:SciTE.exe (4.4.6.0) Keyboard:00000409 OS:WIN_10/2009 CPU:X64 OS:X64 Environment(Language:0409) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Users\ZEN\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\ZEN\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.16.1) from:C:\Program Files (x86)\AutoIt3 input:D:\Temp\Registry_write_read.au3 +>16:18:47 AU3Check ended.rc:0 >Running:(3.3.16.1):C:\Program Files (x86)\AutoIt3\autoit3.exe "D:\Temp\Registry_write_read.au3" +>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop. Error: 0 Status: 1 Error: 0 +>16:18:47 AutoIt3.exe ended.rc:0 +>16:18:48 AutoIt3Wrapper Finished. >Exit code: 0 Time: 2.362  
      The user is a local admin.

      According to the script output, the regwrite call should have succeeded.
      SciTe has been runas admin.
      I've also tried compiling the script and running the resulting exe as admin.

      Obviously I can't see the consolewrite output when I do this, but if the function calls were working then the exe should update the registry.

      After suggestions as to options to try next.
      Also, I tried narrowing down the forum search using arguments like: "regwrite windows 10" or "regwrite windows10" and for some reason had no results on the search; so had to use more general search arguments. Would be interested to know why the above wouldn't work as a search argument.

      Thanks

      VW
    • By nacerbaaziz
      good morning everybody.
      today i liked to share an small example with you
      which it an function to read the registry values as an array
      the result array is 2d array witch
      $a_array[n][0] = value name
      $a_array[n][1] = value Data
      $a_array[0][0] = values count
      here's the function

      #include <Array.au3> #include <WinAPIReg.au3> #include <APIRegConstants.au3> Local $a_array = _RegReadToArray("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run") If @error Then     MsgBox(16, "error", @error)     Exit EndIf _ArrayDisplay($a_array) Func _RegReadToArray($s_RegKey)     Local $a_KeySplitInfo = StringSplit($s_RegKey, "\\", 2)     If UBound($a_KeySplitInfo) <= 1 Then         $a_KeySplitInfo = StringSplit($s_RegKey, "\", 2)         If UBound($a_KeySplitInfo) <= 1 Then Return (1, 1, 0)     EndIf     Local $H_KeyInfo = "", $s_RegKeyInfo = ""     Switch $a_KeySplitInfo[0]         Case "hklm", "HKEY_LOCAL_MACHINE", "hklm64", "HKEY_LOCAL_MACHINE64"             $H_KeyInfo = $HKEY_LOCAL_MACHINE         Case "hkCu", "HKEY_CURRENT_USER", "hkCU64", "HKEY_CURRENT_USER64"             $H_KeyInfo = $HKEY_CURRENT_USER         Case "hkCr", "HKEY_CLASSES_ROOT", "HKCR64", "HKEY_CLASSES_ROOT64"             $H_KeyInfo = $HKEY_CLASSES_ROOT         Case "HKU", "HKEY_USERS", "HKU64", "HKEY_USERS64"             $H_KeyInfo = $HKEY_USERS         Case Else             Return SetError(2, 2, 0)     EndSwitch     _ArrayDelete($a_KeySplitInfo, 0)     $s_RegKeyInfo = _ArrayToString($a_KeySplitInfo, "\")     Local $H_KeyInfoOpen = _WinAPI_RegOpenKey($H_KeyInfo, $s_RegKeyInfo, $KEY_READ)     Local $A_KeyInfo = _WinAPI_RegQueryInfoKey($H_KeyInfoOpen)     If @error Then Return SetError(1, 1, 0)     _WinAPI_RegCloseKey($H_KeyInfoOpen)     Local $A_RegVal[$A_KeyInfo[2] + 1][2]     Local $iV = 1, $s_RegRead = ""     While 1         $s_RegVal = RegEnumVal($s_RegKey, $iV)         If @error <> 0 Then ExitLoop         $s_RegRead = RegRead($s_RegKey, $s_RegVal)         If Not (@error) Then             $A_RegVal[$iV][0] = $s_RegVal             $A_RegVal[$iV][1] = $s_RegRead         EndIf         $iV += 1     WEnd     $A_RegVal[0][0] = UBound($A_RegVal) - 1     If $A_RegVal[0][0] >= 1 Then         Return $A_RegVal     Else         Return SetError(3, 3, 0)     EndIf EndFunc   ;==>_RegReadToArray
      i hope you benefit from it
      with my greetings
    • By Simpel
      Hi,
      I wondered why negative integers I wrote into registry (e.g. negative x-coordinates of a gui if using two monitors and the right one is the main one) wouldn't return right when reading. Now I know: it is saved as an unsigned integer (without algebraic sign). So here is a snippet that is changing unsigned to signed integer:
      Global Const $g_sRegKey = "HKEY_CURRENT_USER\Software\" & @ScriptName ; path to registry RegWrite($g_sRegKey, "Value", "REG_DWORD", -2147483647) ; write some negative integer into registry; -2147483647 highest possible negative integer , 2147483648 highest possible positive integer if talking of 32bit Local $sValue = RegRead($g_sRegKey, "Value") ; read out registry ConsoleWrite("Value: " & $sValue & @CRLF) ; show real value in console Local $sResult = _SignedInteger($sValue) ; change to signed value ConsoleWrite("Result: " & $sResult & @CRLF) ; and show it in console Func _SignedInteger($iUnsignedInteger) Local $iSignedInteger If $iUnsignedInteger > (2^31) Then ; then it means a negative integer $iSignedInteger = $iUnsignedInteger - (2^32) Else $iSignedInteger = $iUnsignedInteger EndIf Return $iSignedInteger EndFunc It took me some time to find out the problem and so I hope I can help somebody with this.
      Regards, Conrad
    • By copyleft
      I've looked at a bunch of SetACL examples on this site and none seem to be able to convert this batch script into a working AutoIt script.
      BATCH
      @echo off "%~dp0setacl.exe" -on "HKEY_CLASSES_ROOT\CLSID\{9C60DE1E-E5FC-40f4-A487-460851A8D915}\DefaultIcon" -ot reg -actn setowner -ownr n:administrators >nul 2>nul "%~dp0setacl.exe" -on "HKEY_CLASSES_ROOT\CLSID\{9C60DE1E-E5FC-40f4-A487-460851A8D915}\DefaultIcon" -ot reg -actn ace -ace "n:administrators;p:full" >nul 2>nul Reg.exe add "HKCR\CLSID\{9C60DE1E-E5FC-40f4-A487-460851A8D915}\DefaultIcon" /ve /t REG_EXPAND_SZ /d "C:\My.ico" /f NON-WORKING AUTOIT
      RunWait('setacl.exe "HKCR64\CLSID\{9C60DE1E-E5FC-40f4-A487-460851A8D915}\DefaultIcon" -ot reg -actn setowner -ownr "n:administrators"') RunWait('setacl.exe "HKCR64\CLSID\{9C60DE1E-E5FC-40f4-A487-460851A8D915}\DefaultIcon" -ot reg -actn setowner -ownr "n:administrators;p:full"') RegWrite('HKCR64\CLSID\{9C60DE1E-E5FC-40f4-A487-460851A8D915}\DefaultIcon', '','REG_EXPAND_SZ','C:\Windows\My.ico') Any ideas on what I'm doing wrong?
       
    • By Elrond5
      So I want to remap Capslock to Ctrl using Autoit
      ;3A00 = Caps ;1D00 = Ctrl RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout","Scancode Map","REG_BINARY","000000000000000002000000E0473A0000000000") However it isn't doing anything. And I have no idea why my code doesn't work.
×
×
  • Create New...