Jump to content



Photo

RegWrite Question


  • Please log in to reply
10 replies to this topic

#1 cmacrun

cmacrun

    Seeker

  • Active Members
  • 13 posts

Posted 18 November 2004 - 09:21 PM

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!







#2 Jos

Jos

    oh joy ...

  • Developers
  • 21,105 posts

Posted 18 November 2004 - 09:25 PM

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                                                                 Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)


#3 cmacrun

cmacrun

    Seeker

  • Active Members
  • 13 posts

Posted 18 November 2004 - 09:31 PM

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.

#4 ezzetabi

ezzetabi

    さくらが さいた

  • Active Members
  • PipPipPipPipPipPip
  • 2,011 posts

Posted 18 November 2004 - 09:31 PM

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?

#5 scriptkitty

scriptkitty

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,274 posts

Posted 18 November 2004 - 09:32 PM

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.

#6 cmacrun

cmacrun

    Seeker

  • Active Members
  • 13 posts

Posted 18 November 2004 - 09:37 PM

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.

#7 ezzetabi

ezzetabi

    さくらが さいた

  • Active Members
  • PipPipPipPipPipPip
  • 2,011 posts

Posted 18 November 2004 - 09:44 PM

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, 18 November 2004 - 09:49 PM.


#8 scriptkitty

scriptkitty

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,274 posts

Posted 18 November 2004 - 09:47 PM

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, 18 November 2004 - 10:02 PM.

AutoIt3, the MACGYVER Pocket Knife for computers.

#9 scriptkitty

scriptkitty

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,274 posts

Posted 18 November 2004 - 10:09 PM

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.

#10 cmacrun

cmacrun

    Seeker

  • Active Members
  • 13 posts

Posted 18 November 2004 - 10:10 PM

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!

#11 this-is-me

this-is-me

    Pursuer of obscure functionality

  • Active Members
  • PipPipPipPipPipPip
  • 2,372 posts

Posted 18 November 2004 - 10:53 PM

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?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users