bat脚本设置系统环境变量即时生效

简介: 关于bat的资料多但零碎,记录一下。1.设置环境变量即时生效:通过重启explorer来实现即时生效(亲测有效)  @echo off  set curPath=%cd%  wmic ENVIRONMENT where "name='path' and username=''" set Va...

关于bat的资料多但零碎,记录一下。

1.设置环境变量即时生效:通过重启explorer来实现即时生效(亲测有效)

  @echo off

  set curPath=%cd%

  wmic ENVIRONMENT where "name='path' and username='<system>'" set VariableValue="%curPath%tool\dig;%path%" 

  taskkill /im explorer.exe /f
  @echo ================================================
  @echo 下面开始重启“explorer.exe”进程
  pause
  start explorer.exe

 

2.变量是否包含另一个变量判断

  set mypath=%path%

  set curPath=%cd%

  set digPath=%curPath%tool\dig
  echo %mypath% | find /i "%digPath%">nul && goto A || goto B
  :A /////系统dig环境变量已经存在
  echo 当前环境变量包含%digPath%
  exit

  :B /////不存在

  echo 当前环境变量不包含%digPath%
  exit

  注意:变量中是否包含字符串,使用同样的方法:echo %mypath% | find /i "ABC">nul && goto A || goto B

3.bat中打开exe程序:打开exe程序前需要先切换到exe所在的根目录

  ::切换到exe所在目录

  cd %curPath%tool
  
::启动程序
  start "" "%curPath%tool\operateToolWPF.exe"

关于bat批处理,推荐一个网站,资料很全:http://www.bathome.net

 

目录
相关文章
|
Windows
电脑win系统开机自动运行批处理、脚本等的方法/开机自动执行bat脚本
电脑win系统开机自动运行批处理、脚本等的方法/开机自动执行bat脚本
905 0
|
8月前
|
Shell Linux Perl
10.2.3 环境变量的功能
10.2.3 环境变量的功能
77 0
|
Shell 开发工具 git
查看系统环境变量
查看系统环境变量
82 0
|
存储 Python Windows
Python 技术篇-设置windows开机自动启用Jupyter服务,BAT批处理脚本启用jupyter服务设置,设置jupyter默认启动位置的方法
Python 技术篇-设置windows开机自动启用Jupyter服务,BAT批处理脚本启用jupyter服务设置,设置jupyter默认启动位置的方法
770 0
Python 技术篇-设置windows开机自动启用Jupyter服务,BAT批处理脚本启用jupyter服务设置,设置jupyter默认启动位置的方法
|
缓存 网络安全 C++
WinDbg的环境变量一览表,代理服务器的设置
WinDbg的环境变量一览表,代理服务器的设置
247 0
|
监控 Shell Linux
|
Shell 应用服务中间件 网络安全
|
Python Shell 开发工具
|
Oracle 关系型数据库 Shell
NSIS添加系统环境变量的方法
A:使用SendMessage ,例子如下: ;修改环境变量 WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "abcd" "ggg" ;刷新环境...
2949 0