Jump to content

Recommended Posts

Posted

Other than going into system -> advanced -> environment variables -> path -> edit and appending a path to the end of it, is there some better/safer way for autoit to do this? (Doing path=%PATH%;c:\program.exe in cmd is not permanent)

Posted

Just use this UDF I use for making a permanent change to the systems path.

; 1st parameter = "User" or "System"
; 2nd parameter = Path to add

; example
_Path('System', '%SystemRoot%\SystemFiles')

Func _Path($type, $value)
    ; adds a folder to permanently become part of the systems path.
    Local $environment, $old, $new, $semicolon
    Switch $type
        Case 'System'
            $environment = 'HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
        Case 'User'
            $environment = 'HKCU\Environment'
        Case Else
        Return
    EndSwitch
    $old = RegRead($environment, 'Path')
    If $old <> '' Then $semicolon = ';'
    If Not StringInStr($old, $value) Then
        $new = $old & $semicolon & $value
        If RegWrite($environment, 'Path', 'Reg_Expand_sz', $new) Then EnvUpdate()
    EndIf
EndFunc

:P

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...