标题: [系统相关] 批处理修改注册表环境变量Path后立即生效(使用三方:dllcall.exe) [打印本页]
作者: cutebe 时间: 2022-3-21 11:42 标题: 批处理修改注册表环境变量Path后立即生效(使用三方:dllcall.exe)
注册表修改环境变量Path后立即生效。
批处理Reg命令修改系统变量后使它立即生效。
刷新系统使系统环境变量修改立即生效。
脚本配置JAVA_HOME环境变量后刷新使其立即生效。- ::广播消息,通知修改了环境变量
- dllcall.exe SendMessageTimeoutA,0xffff,0x1a,0,"Environment",2,5000,0,user32.dll
复制代码
- ::简短写法
- dllcall SendMessageTimeoutA,65535,26,,"Environment",2,4444,,user32
复制代码
适用:一些软件需要用到系统环境变量,如:JAVA要用到JAVA_HOME,数据库要用到Path等。绿色版软件通常用批处理REG命令修改注册表,但问题是不能直接生效,需要重启电脑。运行以上dllcall命令成功广播消息后,再打开的软件载入的是新的环境变量Path/JAVA_HOME等。即对注册表【HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment】项里的修改有效。
----dllcall.exe----
简介:dllcall.exe是一个调用.dll中函数的32位第三方工具。版本:v1.0.3.5,大小:4096字节。
帖子:又一个 dllcall.exe //三方详情介绍
http://bbs.bathome.net/viewthread.php?tid=26870
下载:搜索本论坛
http://www.bathome.net/s/tool/index.html?key=dllcall
或使用如下批处理,生成dllcall.exe- ::生成dllcall_exe.bat::调用DLL函数的dllcall.exe:v1.0.3.5:4096B::
- ::实用:通过广播设置变更的消息,刷新环境变量。
- ::dllcall SendMessageTimeoutA,0xffff,26,0,"Environment",2,5000,,user32.dll
- @echo off
- cd/d%~dp0
- >Base64Bin.js (for /f "tokens=1* delims=:" %%u in ('"type "%~0"|findstr /ib "::JS::""')do echo/%%v)
- for /f "delims=:" %%n in ('findstr /ibnc:"::dllcall.cab" "%~0"')do set "N=%%n"
- >dllcall_base64.txt (for /f "eol=: delims=" %%b in ('more +%N% "%~0"')do echo/%%b)
- Base64Bin.js dllcall_base64.txt
- expand -r dllcall_base64.txt.bin %_解压文件:dllcall.ex_/dllcall.cab_%
- del Base64Bin.js dllcall_base64.txt dllcall_base64.txt.bin %_删除中间生成文件_%
- goto :eof
-
- ::JS:://Base64_to_Bin.js Base64编码的.txt转.exe/.zip/.jpg等
- ::JS:://获取Hex文本文件名参数
- ::JS::TxtFile = WScript.Arguments(0);
- ::JS::
- ::JS:://读取Base64文本文件
- ::JS::var fso = new ActiveXObject("Scripting.FileSystemObject");
- ::JS::var HexFile=fso.OpenTextFile(TxtFile);
- ::JS::HexData=HexFile.ReadAll();
- ::JS::
- ::JS:://转换中间XMLDOM对象,便于处理
- ::JS::var oXML = new ActiveXObject("Microsoft.XMLDOM");
- ::JS::var xNode = oXML.createElement("Base64Data");
- ::JS::xNode.dataType = "bin.base64";
- ::JS::xNode.text = HexData;
- ::JS:://转Stream并写入Bin
- ::JS::var Stream = new ActiveXObject("ADODB.Stream");
- ::JS::Stream.Type = 1;
- ::JS::Stream.Open;
- ::JS::Stream.Write(xNode.nodeTypedValue); //Bin
- ::JS::Stream.SaveToFile(TxtFile + ".bin",2);
- ::JS::Stream.Close;
-
- ::dllcall.cab的Base64Txt文本::dllcall.ex_:2126B::dllcall_base64.txt:2875B::
- TVNDRgAAAABOCAAAAAAAACwAAAAAAAAAAwEBAAEAAAAAAAAASAAAAAEAAQAAEAAAAAAAAAAA
- b1R6ryAAZGxsY2FsbC5leGUA0rDqQf4HABBDS9VXbUxb1xl+r4HwEQx0CoFUynJBICWVsUwT
- Ij6cygQIpCEBYgLRCE1ufC/Y9Ppe637wsbHJFbDE9bJVWv5Nm1QhTdM0TfsRTc0+NKg7d2zr
- j1X9kaib1KndZmRNWSqxJVKXu+fca4xpkVpN+7Ee673nnOc87+e5xz4+/6U4cURUTDVkWUQB
- NkEL0Ke3OKTqyM+q6E75Ww2vcYNvNYyGIzof09RpTYjyIUFRVIO/LvGaqfARhe8dCvJRVZS8
- 7oqmbRvDfUSDnIsuPhwb2cbeo2puP8f1UwVzkANrCoRFx3oXUS5cKrLJucCBf3+OYYU6XD7u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no8C3+b0QnUK2nRjsRaCrgPXKKyLWZawIdu/Jj3iwwtDi4ccE
- N5TX0oGxaHYYvTSIj05edt+navgdtz/M/hyxj5dmbR3Vtu9FryEbtu7HJZ+DtoQ589yDtRgt
- 2JFOwz7773Ae+Y7CjwwsBCaLgX1vnaanoMs0otARgC+g4gJmkm07hBURYxG617HGfywKxvFR
- WUGdxiAarO/UpxU8H+Q4pM3+D8LiHcrFx6yxqLf1lbz33XX1Apu38V57n8eAa3vsJlGT/SaM
- YlWw85TR7+wXUXnx5+/c/T+0/wA=
- ::Base64结束。::
复制代码
附:Win的SendMessageTimeout()消息函数简要说明
SendMessageTimeout(HWND_BROADCAST,WM_SETTINGCHANGE,0,LPARAM("Environment"),SMTO_ABORTIFHUNG,5000,&MsgResult);
user32.dll的SendMessageTimeout()消息函数有7个参数
1、hWnd: HWND_BROADCAST = 0xffff //广播
2、Msg: WM_SETTINGCHANGE = 0x1a //设置更新
3、wParam: = 0
4、lPARAM: = "Environment" //环境变量
5、fuFlags: SMTO_ABORTIFHUNG = 2
6、uTimeout: = 5000
7、(out)lpdwResult: =0
----C++函数原型----
public static extern IntPtr SendMessageTimeout(IntPtr hWnd,uint Msg,UIntPtr wParam,string lParam,uint fuFlags,uint uTimeout,out UIntPtr lpdwResult);
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |