Skip to content

Instantly share code, notes, and snippets.

@tiborepcek
Last active February 4, 2022 12:28
Show Gist options
  • Save tiborepcek/be334bae9a1851796df37626b8c2c57b to your computer and use it in GitHub Desktop.
Save tiborepcek/be334bae9a1851796df37626b8c2c57b to your computer and use it in GitHub Desktop.
This script writes the path of its folder to user PATH environment (HKEY_CURRENT_USER\Environment - Path). First it checks, if the path exists, and if not, then gives the option to write it.
#cs
write_this_folder_to_user_path_env.au3 | version 1.0 | written in AutoIt 3
Description: This script writes the path of its folder to user PATH environment
(HKEY_CURRENT_USER\Environment - Path). First it checks, if the path exists,
and if not, then gives the option to write it.
Author: Tibor Repček
Web: https://gist.github.com/tiborepcek/be334bae9a1851796df37626b8c2c57b
#ce
$currentUserPaths = RegRead("HKEY_CURRENT_USER\Environment", "Path")
$thisFolderDirectory = @ScriptDir
If StringInStr($currentUserPaths, $thisFolderDirectory) = 0 Then ;path not in user path environment
$question = MsgBox(4, "Question", $thisFolderDirectory & @CRLF & @CRLF & "This path does not exist in user PATH environment. Do you want to write it to the user PATH environment?")
If $question = 6 Then ;YES button pressed
RegWrite("HKEY_CURRENT_USER\Environment", "Path", "REG_EXPAND_SZ", ";" & $currentUserPaths & $thisFolderDirectory & ";")
Else ;NO button pressed
Exit
EndIf
Else ;path already exists in user path environment
MsgBox(64, "Exiting", $thisFolderDirectory & @CRLF & @CRLF & "This path already exists in user PATH environment. This script ends now without writing new path to the user PATH environment.")
EndIf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment