kodius Posted April 13, 2009 Share Posted April 13, 2009 I want to append to the PATH, I'm close but just can't figure this part out... I found some of this code in another topic ; Append to PATH Func _ToolKit() $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 $path1 = $sSep & "c:\program files\mytools" $path2 = $path & $path1 RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", $path2) If @error <> 0 Then RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "PATH", $sType, $path2) EndFunc ;==>_ToolKit Link to comment Share on other sites More sharing options...
PsaltyDS Posted April 13, 2009 Share Posted April 13, 2009 I want to append to the PATH, I'm close but just can't figure this part out... I found some of this code in another topic: ; Append to PATH Func _ToolKit() $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 $path1 = $sSep & "c:\program files\mytools" $path2 = $path & $path1 RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", $path2) If @error <> 0 Then RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "PATH", $sType, $path2) EndFunc ;==>_ToolKit What was the point of the second RegRead() and error checking before RegWrite()? Also, I don't think PATH will ever be a REG_MULTI_SZ type, so that check is probably a waste of time and effort. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
DaRam Posted April 13, 2009 Share Posted April 13, 2009 Modified function (below), use it like this:_Append2Path "C:\Program Files\Another Path"Func _Append2Path($Path2Append) Const $RegPath = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" Local $sSep = ";", $sType = "REG_SZ", $nPath Local $oPath = RegRead($RegPath, "PATH") If @extended = 7 Then $sSep = @LF $sType = "REG_MULTI_SZ" EndIf $nPath = $oPath & $sSep & $Path2Append RegWrite($RegPath, "PATH", $sType, $nPath) EndFuncYou are passing the Path you want appended to the Function as a parameterThe function reads the existing path from the Registry,If the @EXTENDED macro (set by the call to RegRead) is 7, then type of the value and separator variable are changed.The new Path variable is build using the separator and written back to the registry. Link to comment Share on other sites More sharing options...
PsaltyDS Posted April 13, 2009 Share Posted April 13, 2009 Modified function (below), use it like this: _Append2Path "C:\Program Files\Another Path" Func _Append2Path($Path2Append) Const $RegPath = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" Local $sSep = ";", $sType = "REG_SZ", $nPath Local $oPath = RegRead($RegPath, "PATH") If @extended = 7 Then $sSep = @LF $sType = "REG_MULTI_SZ" EndIf $nPath = $oPath & $sSep & $Path2Append RegWrite($RegPath, "PATH", $sType, $nPath) EndFunc You are passing the Path you want appended to the Function as a parameter The function reads the existing path from the Registry, If the @EXTENDED macro (set by the call to RegRead) is 7, then type of the value and separator variable are changed. The new Path variable is build using the separator and written back to the registry. But when is PATH ever going to be a REG_MULTI_SZ type? I think that whole check can safely go away. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
DaRam Posted April 13, 2009 Share Posted April 13, 2009 Agree, just did not spend more time than necessary on this. But when is PATH ever going to be a REG_MULTI_SZ type? I think that whole check can safely go away. Link to comment Share on other sites More sharing options...
kodius Posted April 13, 2009 Author Share Posted April 13, 2009 If I re-run the script it keeps appending to the PATH, thanks for your help but how do I RegRead before appending to see if the value is already in the string? something like this? If RegRead($RegPath & $Path2Append) Then @error <> 0 Then RegWrite ($RegPath, "PATH", $sType, $nPath) Link to comment Share on other sites More sharing options...
DaRam Posted April 13, 2009 Share Posted April 13, 2009 Use this: Func _Append2Path($Path2Append) Const $RegPath = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" Local $sSep = ";", $sType = "REG_SZ", $nPath Local $oPath = RegRead($RegPath, "PATH") If @extended = 7 Then $sSep = @LF $sType = "REG_MULTI_SZ" EndIf If StringInStr($oPath, $Path2Append) < 1 Then $nPath = $oPath & $sSep & $Path2Append RegWrite($RegPath, "PATH", $sType, $nPath) EndIf EndFunc Link to comment Share on other sites More sharing options...
kodius Posted April 13, 2009 Author Share Posted April 13, 2009 Use this: Func _Append2Path($Path2Append) Const $RegPath = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" Local $sSep = ";", $sType = "REG_SZ", $nPath Local $oPath = RegRead($RegPath, "PATH") If @extended = 7 Then $sSep = @LF $sType = "REG_MULTI_SZ" EndIf If StringInStr($oPath, $Path2Append) < 1 Then $nPath = $oPath & $sSep & $Path2Append RegWrite($RegPath, "PATH", $sType, $nPath) EndIf EndFunc Thanks DaRam you are DaMan! That worked perfectly! 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