PerryRaptor Posted February 18, 2004 Share Posted February 18, 2004 $c = "9999.exe" ;next two lines are all one line... $d = RegRead("HKEY_Local_Machine\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "MyNewStringValue") If $c <> $d Then ;next two lines are all one line... RegWrite("HKEY_Local_Machine\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "MyNewStringValue", "REG_SZ", $c) EndIf The If $c <> $d Then... doesn't work if the registry key doesn't exisit. If I manually create the key with or without a value then it works fine. According to the AutoIT3 Helpfile, RegRead() will return the value of the key if no errors are encountered. RegRead() errors will return either 1, -1, or 2. So regardless of the value of $d, it will not be <> to $c, therefore, the registry key should be created and the value of $c written. What am I missing? Link to comment Share on other sites More sharing options...
Valik Posted February 18, 2004 Share Posted February 18, 2004 RegRead sets @error, you need to check that, not the return value. Link to comment Share on other sites More sharing options...
CyberSlug Posted February 18, 2004 Share Posted February 18, 2004 (edited) EDIT: Make sure you are using the newest AutoIt version.It *might* be a number-to-string conversion problemRegRead Failure: Returns numeric 1 and sets the @error flag:Try this:If String($c) <> String($d)Another Edit: Why not just write the key without reading it? Edited February 18, 2004 by CyberSlug Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
redndahead Posted February 18, 2004 Share Posted February 18, 2004 My guess is that the variable doesn't get assigned anything if it is not there. So I would change to this. $d = "NullValue" $c = "9999.exe" ;next two lines are all one line... $d = RegRead("HKEY_Local_Machine\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "MyNewStringValue") If $c <> $d Then ;next two lines are all one line... RegWrite("HKEY_Local_Machine\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "MyNewStringValue", "REG_SZ", $c) EndIf Assign a start value for $d that will never occur and then if there is no value assigned then your comparison is ok. Also you can do $c = "9999.exe" ;next two lines are all one line... $d = RegRead("HKEY_Local_Machine\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "MyNewStringValue") If @Error = 1 OR $c <> $d Then ;next two lines are all one line... RegWrite("HKEY_Local_Machine\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "MyNewStringValue", "REG_SZ", $c) EndIf If the registry key doesn't exist it still writes $c to the registry. Hope this helps red Link to comment Share on other sites More sharing options...
PerryRaptor Posted February 18, 2004 Author Share Posted February 18, 2004 $d = "as12" ...nope If @Error = 1 OR $c <> $d Then...nope If $c <> String($d)...nope None of these thre will work. I get the exact same error each time. $d = RegRead("HKEY_Local_Machine\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "MyNewStringValue") Error: Unable to read/write the requested registry key. Link to comment Share on other sites More sharing options...
Valik Posted February 18, 2004 Share Posted February 18, 2004 Wait, is this a message box popping up with an error or something? Link to comment Share on other sites More sharing options...
PerryRaptor Posted February 18, 2004 Author Share Posted February 18, 2004 Yes, AutoIT Error with the line $d = RegRead("HKEY_Local_Machine\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "MyNewStringValue") Link to comment Share on other sites More sharing options...
PerryRaptor Posted February 18, 2004 Author Share Posted February 18, 2004 Yes, it is case sensitive "HKEY_LOCAL_MACHINE" must be in all caps...Never would have figured that one out by myself!!! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now