
[已解決]批處理怎樣比較版本并重啟進程我想讓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.0UGSLicensingnx_flexugslmd.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.0UGSLicensingnx_flex* %AllUsersProfile%nx_flex
- tasklist | find lmgrdm.exe
- if errorlevel 1 %AllUsersProfile%nx_flexPLMstart.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
nclick="copycode($('code0'));">復制代碼
結果,當%%1 LSS %%2成立時,執行批處理后沒什么反應,而且$和1.txtc、2.txt都沒有刪除,請哪位老師幫我看看,謝謝!