Sign in to follow this  
Followers 0
cmacrun

RegWrite Question

11 posts in this topic

I am attempting to read in a reg value, append some data to that value and the write it back to the same key. The data I'm reading is contains Env. Variables such as %systemdrive%. When I read it into a variable, autoit converts it to the literal or C:\. I can work around this by doing a string replace, but when I do a RegWrite, I get C:\ back into the registry. Any ideas how to get Rewrite to write %systemdrive% instead of C:\?

I have tried using Opt(ExpandEnvStrings, 1/0) to no avail. Any help would be appreciated!

Share this post


Link to post
Share on other sites



I am attempting to read in a reg value, append some data to that value and the write it back to the same key.  The data I'm reading is contains Env. Variables such as %systemdrive%.  When I read it into a variable, autoit converts it to the literal or C:\.  I can work around this by doing a string replace, but when I do a RegWrite, I get C:\ back into the registry.  Any ideas how to get Rewrite to write %systemdrive% instead of C:\?

I have tried using Opt(ExpandEnvStrings, 1/0) to no avail.  Any help would be appreciated!

<{POST_SNAPBACK}>

why first convert it and then change it back to %systemdrive% ?

maybe you can explain what you want to accomplish and post what you have ?


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

why first convert it and then change it back to %systemdrive% ?

maybe you can explain what you want to accomplish and post what you have ?

<{POST_SNAPBACK}>

I'm not trying to convert it actually. RegRead and RegWrite are converting it for me... Anyway I'm trying to read in the "Path" info, which contains Env. Variables, specifically, %systemdrive%. I want to write back to the registry what I read out, not C:\.

Thanks.

Share this post


Link to post
Share on other sites

I just tried and I don't have this problem.

Script I tested:

RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE", "TestKey", "REG_SZ", "%windir%")

$a = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE", "TestKey")
RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE", "TestKey")

MsgBox(0,'',$a)

What OS are you using?

Share this post


Link to post
Share on other sites

Funny, does this show %systemdrive% or c:\

I get %systemdrive% returned

RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE", "TestKey", "REG_SZ", "%systemdrive%")

$var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE", "TestKey")
MsgBox(1,"",$var)

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

Funny, does this show %systemdrive% or c:\

I get %systemdrive% returned

RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE", "TestKey", "REG_SZ", "%systemdrive%")

$var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE", "TestKey")
MsgBox(1,"",$var)

<{POST_SNAPBACK}>

I must be retarded then. I have XP Pro SP1 installed on this packaging machine. Not sure what the deal is. The only thing I see here is that you are creating the key, and I'm overwriting one that is already created. They key type is a bit different too, yours being REG_SZ, mine being REG_EXPAND_SZ. Test it with that key type and let me know.

Thanks.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

No difference:

RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE", "TestKey", "REG_EXPAND_SZ", "DoomedKey")
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE", "TestKey", "REG_EXPAND_SZ", "%windir%");So it overwrites.

$a = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE", "TestKey")
RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE", "TestKey")

MsgBox(0,'',$a)

cmacrun can you try OURS script?

(mine will delete the key so you wont leave a trace...)

Edited by ezzetabi

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

No change. What about on yours?

RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE", "TestKey1", "REG_EXPAND_SZ", "%systemdrive%")

$var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE", "TestKey1")
MsgBox(1,"",$var)

test your code first by displaying what was read, and rigth before you put it back. I am thinking your script is converting it when you process it.

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

Ok, on win2k, I found a few env variables. Works fine here with this code.

I read what is there, and overwrite it, and then read it again.

$var = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", "Recent")
MsgBox(1,"Test1",$var)
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", "Recent", "REG_EXPAND_SZ", $var)
$var2 = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", "Recent")
MsgBox(1,"Test2",$var2)

Just to make sure, I changed it to test and wrote the original back.

$var = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", "Recent")
MsgBox(1,"Test1",$var)
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", "Recent", "REG_EXPAND_SZ", $var & "1")
$var2 = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", "Recent")
MsgBox(1,"Test2",$var2)
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", "Recent", "REG_EXPAND_SZ", $var)

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

No change. What about on yours?

RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE", "TestKey1", "REG_EXPAND_SZ", "%systemdrive%")

$var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE", "TestKey1")
MsgBox(1,"",$var)

test your code first by displaying what was read, and rigth before you put it back. I am thinking your script is converting it when you process it.

<{POST_SNAPBACK}>

Ok this is strange, when I look at the actual registry value, it shows %systemdrive%, but when I go through system properties, it shows C:\. This was not happening prior to running the script, so it must be something with the way the OS is processing the key after being modified. Go figure. Thanks for the prompt responses on this. Sorry for the false alarm!

Share this post


Link to post
Share on other sites

Glad I saw this... You can't change the _actual_ systemdrive variable in the registry, because windows knows better. You can, however do a subst from the command line to create a new drive letter for an existing drive.


Who else would I be?

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