直接上项目中代码,实际中如果电脑缺少C:\Windows\System32路径的话,下面的程序也无法运行,因为cmd中的一些命令需要该路径下的一些文件
@echo off
@set Path_=C:\Windows\System32 ::设置Path_为你想要的路径echo %Path%|find /i "%Path_%" && set IsNull=true|| set IsNull=false ::判断 Path是否包含Path_
if not %IsNull%==true (
::如果不包含,在Path末尾加上Path_
reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment" /v Path /t REG_EXPAND_SZ /d "%Path%;%Path_%" /f)
下面代码为项目中使用到的MSCOMM32.OCX控件,因为有的电脑上并没有安装该控件,所以在这里判断电脑系统种类进行复制和注册
if exist C:\Windows\SysWOW64 (copy %~dp0\MSCOMM32.OCX C:\Windows\SysWOW64\MSCOMM32.OCX.
regsvr32 C:\Windows\SysWOW64\MSCOMM32.OCX.
) else (
copy %~dp0\MSCOMM32.OCX C:\Windows\System32\MSCOMM32.OCX.
regsvr32 C:\Windows\System32\MSCOMM32.OCX.
)