修改path环境变量SysEnv

#NoTrayIcon
#SingleInstance, Force
#NoEnv ; somewhat ironic...
;Thinkai添加命令行 命令行仅添加进path,不是覆盖
;出处:http://www.autohotkey.com/board/topic/63210-modify-system-path-gui
if 0 = 0
	{

		; this won't work in vista/7 if it's not run as an administrator.
		; i'm too lazy to request it manually so the easiest way is to
		; compile this script, and then under Compatibility tab in the
		; compiled exe's Properties select "Run as Administrator"

		RegRead, P, HKLM, SYSTEMCurrentControlSetControlSession ManagerEnvironment, PATH

		Gui, +Delimiter`;

		width := 400
		Gui, Add, Text, w%width%, Double Click an entry to modify it. Click Add to make a new entry and Delete to remove the selected entry.
		Gui, Add, ListBox, vSysPath w%width% r8 +0x100 gEditEntry AltSubmit, %P%
		Gui, Font, s12
		Gui, Add, Button, gNew    w70 section  , New
		Gui, Add, Button, gDelete w70 ys xs+74 , Delete
		Gui, Add, Button, gExit   w70 ys xs+330, Cancel
		Gui, Add, Button, gSubmit w70 ys xp-74, Submit
		Gui, Show, , SysEnv -- Change System Environment Variable
	return
	}
Else
	{
	addpath = %1%
	RegRead, oldpath, HKLM, SYSTEMControlSet001ControlSession ManagerEnvironment, Path
	RegWrite, REG_SZ, HKLM, SYSTEMControlSet001ControlSession ManagerEnvironment, Path, %oldpath%;%addpath%
	RegWrite, REG_SZ, HKLM, SYSTEMCurrentControlSetControlSession ManagerEnvironment, Path, %oldpath%;%addpath%
	SendMessage, 0x1A, 0,"Environment",, ahk_id 0xFFFF
	ExitApp
	}

EditEntry:
	if (a_guievent == "DoubleClick" && a_eventinfo) {
		Gui +OwnDialogs
		RegExMatch(P, "P)^(?:(?[^;]*)(?:;|$)){" a_eventinfo "}", _)
		_En := IB( "Edit PATH entry", substr(P, _PosE, _LenE))
		if (ErrorLevel == 0)
		{
			if (InStr(FileExist(ExpEnv(_En)),"D"))
			{
				rP := substr(P, 1, _PosE-1) _En (_PosE+_LenE+1  0 ? ";" : "") add
		GuiControl, , SysPath, `;%P%
	}
return

Delete:
	GuiControlGet, entry, , SysPath
	if (entry) {
		Gui, +OwnDialogs
		MsgBox, 4, SysEnv -- Confirm, Remove entry #%entry% from PATH?
		IfMsgBox Yes
		{
			RegExMatch(P, "P)^(?:(?[^;]*)(?:;|$)){" entry "}", _)
			P := SubStr(P, 1, max(_PosE-2,0)) (_PosE+_LenE+1  b ? a : b
}

ExpEnv(str) {
	; by Lexikos: http://www.autohotkey.com/forum/viewtopic.php?p=327849#327849
	if sz:=DllCall("ExpandEnvironmentStrings", "uint", &str, "uint", 0, "uint", 0)
	{
		VarSetCapacity(dst, A_IsUnicode ? sz*2:sz)
		if DllCall("ExpandEnvironmentStrings", "uint", &str, "str", dst, "uint", sz)
			return dst
	}
	return ""
}

给TA捐赠
共{{data.count}}人
人已捐赠
其他案例

谢芳菲|文本可间断复制神器

2020-3-8 14:47:21

其他教程

图种小工具

2020-3-9 1:56:44

个人中心
购物车
优惠劵
有新私信 私信列表
搜索