Jump to content

RegRead-RegWrıte Bıg Problem


Recommended Posts

Hello I used THIS code for add a value ın environment of PATH.

When I run my program everything look like normal. I am seeIng new values In Environment tab. But my path broken completely. Now All path env. doesn't work.

In command prompt I trying to run IPCONFIG. IT Is sayıng Path not found.

maybe It Is a bug maybe wrong code.

when I delete "PATH" so add again problem resolving.

Can anyone help me.

CODE
$path = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment","PATH")

$path2 = ";c:\Program Files\Microsoft Office\OFFICE11"

$path3 = ";c:\Program Files\Microsoft Office\OFFICE12"

$path4 = $path & $path2 & $path3

RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment","PATH","REG_SZ", $path4)

Startup Agent It is my small Startup Agent. You can install programs on startup Domain pc without Admin rights.
Link to comment
Share on other sites

Hello I used THIS code for add a value ın environment of PATH.

When I run my program everything look like normal. I am seeIng new values In Environment tab. But my path broken completely. Now All path env. doesn't work.

In command prompt I trying to run IPCONFIG. IT Is sayıng Path not found.

maybe It Is a bug maybe wrong code.

when I delete "PATH" so add again problem resolving.

Can anyone help me.

CODE
$path = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment","PATH")

$path2 = ";c:\Program Files\Microsoft Office\OFFICE11"

$path3 = ";c:\Program Files\Microsoft Office\OFFICE12"

$path4 = $path & $path2 & $path3

RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment","PATH","REG_SZ", $path4)

That's right, it won't be found. First thing is Restore your system to before you tried to change the registry and then come back for instructions.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

The only wrong thing I can see in your code is the registry type. I'm using windows XP Sp3 and when I look at the registry key that you are trying to update the type is REG_EXPAND_SZ not REG_SZ.

I have found same reason. I think problem is this.

I dont know how can I resolve problem in 1500 computer.

Startup Agent It is my small Startup Agent. You can install programs on startup Domain pc without Admin rights.
Link to comment
Share on other sites

Read the help file for RegRead()

When reading a REG_MULTI_SZ key the multiple entries are separated by @LF - use with StringSplit(..., @LF) to get each entry.

@EXTENDED is set to the type of the value $REG_... .

So Run this and read the results.

$path = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment","PATH")
msgBox(0, "Results","Key Type = " & @Extended & @CRLF & @CRLF & $Path)

If Key Type = 7 Then you have to use StringSplit($Path, @LF)

Then You go and read the same precautions in the help page for RegWrite()

EDIT:

I should have mentioned that on my XP system that key is REG_SZ (type 1) while on Win 7 (and presumably Vista) it is REG_MULTI_SZ (type 7)

That means that to do both types of systems You will have to conditionally create the values to write based on @Extended.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

$sSep = ";"
$sType = "REG_SZ"
$path = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment","PATH")
If @Extended = 7 Then
    $sSep = @LF
    $sType = "REG_MULTI_SZ"
EndIf
$path2 = $sSep & "c:\Program Files\Microsoft Office\OFFICE11"
$path3 = $sSep & "c:\Program Files\Microsoft Office\OFFICE12"
$path4 = $path & $path2 & $path3
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment","PATH",$sType, $path4)

Edit for syntax error

EDIT 2: BTW, I wouldn't hard code the Office paths in there. Get them from the registry as well. They could be different on different systems. If You are going to hard code them then use the @ProgramFilesDir Macro instead of c:\Program Files because that is even variable by locale.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

$sSep = ";"
$sType = "REG_SZ"
$path = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment","PATH")
If @Extended = 7 Then
    $sSep = @LF
    $sType = "REG_MULTI_SZ"
EndIf
$path2 = $sSep & "c:\Program Files\Microsoft Office\OFFICE11"
$path3 = $sSep & "c:\Program Files\Microsoft Office\OFFICE12"
$path4 = $path & $path2 & $path3
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment","PATH",$sType, $path4)

Edit for syntax error

EDIT 2: BTW, I wouldn't hard code the Office paths in there. Get them from the registry as well. They could be different on different systems. If You are going to hard code them then use the @ProgramFilesDir Macro instead of c:\Program Files because that is even variable by locale.

I going to resolve my problem like that. I select easy method. I will use your example in next programs.

Thanks everybody.

$path = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment","PATH")

RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment","PATH","REG_EXPAND_SZ", $path)

Startup Agent It is my small Startup Agent. You can install programs on startup Domain pc without Admin rights.
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...