友
我使用EnvSet函数设置环境变量,然后使用EnvUpdate函数。这不会永久设置环境变量。当我退出AutoIt脚本时,变量保留其原始值。如何从AutoIt脚本中永久设置环境变量?
萨米尔
答案 0 :(得分:1)
尝试使用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
If StringInStr($oPath, $Path2Append) < 1 Then
$nPath = $oPath & $sSep & $Path2Append
RegWrite($RegPath, "PATH", $sType, $nPath)
EndIf
EndFunc
我也发现了这个用于temp:
RegWrite("HKEY_CURRENT_USER\Environment", "Temp", "REG_SZ", "C:\Temp")
RegWrite("HKEY_CURRENT_USER\Environment", "Tmp", "REG_SZ", "C:\Temp")
EnvUpdate()
Sleep(1000)
EnvSet("Temp", "C:\Temp")
EnvSet("Tmp", "C:\Temp")