Board logo

标题: [系统相关] 批处理修改注册表环境变量Path后立即生效(使用三方:dllcall.exe) [打印本页]

作者: cutebe    时间: 2022-3-21 11:42     标题: 批处理修改注册表环境变量Path后立即生效(使用三方:dllcall.exe)

注册表修改环境变量Path后立即生效。
批处理Reg命令修改系统变量后使它立即生效。
刷新系统使系统环境变量修改立即生效。
脚本配置JAVA_HOME环境变量后刷新使其立即生效。
  1. ::广播消息,通知修改了环境变量
  2. dllcall.exe SendMessageTimeoutA,0xffff,0x1a,0,"Environment",2,5000,0,user32.dll
复制代码
  1. ::简短写法
  2. 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
  1. ::生成dllcall_exe.bat::调用DLL函数的dllcall.exe:v1.0.3.5:4096B::
  2. ::实用:通过广播设置变更的消息,刷新环境变量。
  3. ::dllcall SendMessageTimeoutA,0xffff,26,0,"Environment",2,5000,,user32.dll
  4. @echo off
  5. cd/d%~dp0
  6. >Base64Bin.js (for /f "tokens=1* delims=:" %%u in ('"type "%~0"|findstr /ib "::JS::""')do echo/%%v)
  7. for /f "delims=:" %%n in ('findstr /ibnc:"::dllcall.cab" "%~0"')do set "N=%%n"
  8. >dllcall_base64.txt (for /f "eol=: delims=" %%b in ('more +%N% "%~0"')do echo/%%b)
  9. Base64Bin.js dllcall_base64.txt
  10. expand -r dllcall_base64.txt.bin %_解压文件:dllcall.ex_/dllcall.cab_%
  11. del Base64Bin.js dllcall_base64.txt dllcall_base64.txt.bin %_删除中间生成文件_%
  12. goto :eof
  13. ::JS:://Base64_to_Bin.js Base64编码的.txt转.exe/.zip/.jpg等
  14. ::JS:://获取Hex文本文件名参数
  15. ::JS::TxtFile = WScript.Arguments(0);
  16. ::JS::
  17. ::JS:://读取Base64文本文件
  18. ::JS::var fso = new ActiveXObject("Scripting.FileSystemObject");
  19. ::JS::var HexFile=fso.OpenTextFile(TxtFile);
  20. ::JS::HexData=HexFile.ReadAll();
  21. ::JS::
  22. ::JS:://转换中间XMLDOM对象,便于处理
  23. ::JS::var oXML  = new ActiveXObject("Microsoft.XMLDOM");
  24. ::JS::var xNode = oXML.createElement("Base64Data");
  25. ::JS::xNode.dataType = "bin.base64";
  26. ::JS::xNode.text = HexData;
  27. ::JS:://转Stream并写入Bin
  28. ::JS::var Stream  = new ActiveXObject("ADODB.Stream");
  29. ::JS::Stream.Type = 1;
  30. ::JS::Stream.Open;
  31. ::JS::Stream.Write(xNode.nodeTypedValue); //Bin
  32. ::JS::Stream.SaveToFile(TxtFile + ".bin",2);
  33. ::JS::Stream.Close;
  34. ::dllcall.cab的Base64Txt文本::dllcall.ex_:2126B::dllcall_base64.txt:2875B::
  35. TVNDRgAAAABOCAAAAAAAACwAAAAAAAAAAwEBAAEAAAAAAAAASAAAAAEAAQAAEAAAAAAAAAAA
  36. b1R6ryAAZGxsY2FsbC5leGUA0rDqQf4HABBDS9VXbUxb1xl+r4HwEQx0CoFUynJBICWVsUwT
  37. Ij6cygQIpCEBYgLRCE1ufC/Y9Ppe637wsbHJFbDE9bJVWv5Nm1QhTdM0TfsRTc0+NKg7d2zr
  38. j1X9kaib1KndZmRNWSqxJVKXu+fca4xpkVpN+7Ee673nnOc87+e5xz4+/6U4cURUTDVkWUQB
  39. NkEL0Ke3OKTqyM+q6E75Ww2vcYNvNYyGIzof09RpTYjyIUFRVIO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zY6J2R/
  54. JoocjA9bN7I1MxW7OQl3oiVAd9ljIuXQyzPP2fRPkhnjHBh12699vIsd8yL+XPav6R6OkHnq
  55. UuIvyb6aN+OvIeY7+JZiPW28XkPhukMF+7CpP7GssY8SaRzjfWdg86SfN7b85cbDC90O0Azg
  56. AwDv+RvNv8e/hrP9N2ehEsCWDTzIvpP4zQup4Nh467tWb9OB5GJTfdJoqvnIIT6fN9nTcaXp
  57. QPXtdQd/FvifgN/3NxoV8cecWXSztD/7vrNYC+ulzLr59lB+7YNb/VbrRry90XTdLLtZnext
  58. qr/6wsTrlXSX/QC0vv2vhxfL13A2P8QGXq70/TDl92n7/B1zrva1VPHBne/tDH632jE/WreD
  59. /RPYibq9v+dflDRFko8/6xVlmSiqz4Y0wxkTybDzZcg3IN+D/BjyC8hvIfcgGcgjSBVsP52z
  60. /9/oEPXNR4xhTQ1Juo5Zv2T0qNGooIiDEUXqdhC23C2KmkNhSNAQB8CRJXsuq9cFuVuW1VB+
  61. dkaTCtYG1dCLO7NLipybD6oC/FzXBG2BuaLzpmxETi8Y0qg6HhGlnrCgAR3XIoZ0JmI7k3VD
  62. kyXFZgeQw/O5PArHRCAZql3HmBZRjCn8jspySJBlD3vwRljip0wlZERURWe3IAb0Dg7q3vJZ
  63. SdOBdvKtXp/3uLfNXeGuuKQL01InnzPBT7SEF1u00KTHv22DV4So9JxnYsI3v9jcbELUCXES
  64. nTYZE3DtkgxJO6ofm/R6vR4//Dj8iWcWWya7PmYElC6Iu6JvXojGZEnvdFfweddBWZJinlaf
  65. z+cpfHm6zmNnEONpdX7c42lECAMSdoOfUzVZbGj0AMAWRmOGp9Vj6pLmaLWw3EYXYhLf2BJu
  66. 5A2V18PqHGqB+2JYkmPlPK+j8J383NycdzaiqCHBq2rT7go6q8wKckTM15DXDcGQopJi8I3N
  67. emMBQ9CmTYbryIh6BCSJ26eMXbdLzsis7mxxdHueNxrK0aciisgY3bw0H5Ji9poaCpmaJHoi
  68. OT/5MvOYmxKPFPSYFIpMRSRb93PXdu7enH0VrXeu9rvw3BX5EzhrA5DLWDQK7q+G6wSeYxSk
  69. q3j20UWMztIQXcD8LJ5nMGbtl8UPnjh2OCpxbuy7WvGum7vT3uEYFiSDNIqQQtOwFiGZJFhW
  70. aIpUcH5ic3x0AtJh933EIpqno8C3+b0QnUK2nRjsRaCrgPXKKyLWZawIdu/Jj3iwwtDi4ccE
  71. N5TX0oGxaHYYvTSIj05edt+navgdtz/M/hyxj5dmbR3Vtu9FryEbtu7HJZ+DtoQ589yDtRgt
  72. 2JFOwz7773Ae+Y7CjwwsBCaLgX1vnaanoMs0otARgC+g4gJmkm07hBURYxG617HGfywKxvFR
  73. WUGdxiAarO/UpxU8H+Q4pM3+D8LiHcrFx6yxqLf1lbz33XX1Apu38V57n8eAa3vsJlGT/SaM
  74. YlWw85TR7+wXUXnx5+/c/T+0/wA=
  75. ::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