我想让ugslmd.exe这个进程和现在的ugslmd.exe进行版本比较,如果现在的版本高,就结束进程lmgrdm.exe和lmgrd.exe(这两个结束,ugslmd.exe就会自动结束进程),并且要移除ugslmd.exe,删除"%AllUsersProfile%\nx_fle文件夹,再拷贝、再启动等等;如果现在的版本低就什么都不做。
我根据apang 提供的代码自己拼凑了如下代码(该批处理和NX 10.0文件夹在同一个目录里面):- @echo off
- wmic process where name="ugslmd.exe" get executablepath|find /i /v "exec">c:\1.txt
- setlocal enabledelayedexpansion
- set aa=ugslmd.exe
- set bb=
- for /f "delims=" %%i in (c:\1.txt) do (
- set str=%%i
- set "str=!str:%aa%=%bb%!"
- echo !str!|find "\">>c:\2.txt
- )
- for /f "delims=" %%j in (c:\2.txt) do set ph=%%j
- set sss=%ph%
- :intercept
- if "%sss:~-1%"==" " set "sss=%sss:~0,-1%"&goto intercept
- set "dstFile=%sss%ugslmd.exe"
- set "srcFile=%~dp0NX 10.0\UGSLicensing\nx_flex\ugslmd.exe"
- >$ echo fso = new ActiveXObject("Scripting.FileSystemObject")
- >>$ echo v1 = fso.GetFileVersion("%dstFile:\=/%")
- >>$ echo v1 = v1.replace(/\d+/g,function(s0){return s0-0+100000000})
- >>$ echo v2 = fso.GetFileVersion("%srcFile:\=/%")
- >>$ echo v2 = v2.replace(/\d+/g,function(s0){return s0-0+100000000})
- >>$ echo WScript.Echo(v1 + " " + v2)
- for /f "tokens=1,2" %%1 in ('cscript -nologo -e:jscript $') do (
- if "%%1" LSS "%%2"
- TASKKILL /F /IM lmgrdm.exe /T
- TASKKILL /F /IM lmgrd.exe /T
- move "%sss%ugslmd.exe" "%sss%ugslmd_bak.exe"
- rd /s /q "%AllUsersProfile%\nx_fle
- xcopy /s /e /q /r /y "%~dp0NX 10.0\UGSLicensing\nx_flex\*" "%AllUsersProfile%\nx_flex\"
- tasklist | find "lmgrdm.exe"
- if errorlevel 1 "%AllUsersProfile%\nx_flex\PLMstart.exe" ping 127.1 -n 5 >nul
- )
- del /f/q/a $
- del /f/q/a c:\1.txt
- del /f/q/a c:\2.txt
- endlocal
复制代码 结果,当"%%1" LSS "%%2"成立时,执行批处理后没什么反应,而且$和1.txtc、2.txt都没有删除,请哪位老师帮我看看,谢谢! |