找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 69945|回复: 15

[文件操作] [已解决]批处理怎样比较版本并重启进程?

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

评分

参与人数 1PB +2 收起 理由
Batcher + 2

查看全部评分

 楼主| 发表于 2015-6-20 08:26:57 | 显示全部楼层
看来大家今天都放假休息了
 楼主| 发表于 2015-6-20 16:57:00 | 显示全部楼层
老大在吗,能不能帮我修改一下代码,着急啊,等一天了
 楼主| 发表于 2015-6-21 07:45:50 | 显示全部楼层
自己再顶顶,顶出好心人
 楼主| 发表于 2015-6-22 07:22:07 | 显示全部楼层
再顶顶看,说句话也行啊,求求各位啦
发表于 2015-6-22 10:22:47 | 显示全部楼层
版本号怎样组合的 字母或者数字 发来参考一下
发表于 2015-6-23 00:32:22 | 显示全部楼层
本帖最后由 terse 于 2015-6-23 00:33 编辑
  1. @echo off
  2. for /f "skip=1 delims=" %%i in ('wmic process where name^="ugslmd.exe" get executablepath') do (
  3.     for /f "tokens=*" %%i in ("%%i") do set "ph=%%~dpi"
  4. )
  5. if "%ph%" neq "" for /f "delims=" %%a in ('replace "ugslmd.exe" "%ph:~,-1%" /r /u') do (
  6.     for %%i in (lmgrdm lmgrd) do taskkill /f /im %%i.exe 2>nul
  7.     rd /s /q "%AllUsersProfile%\nx_fle"
  8.     xcopy /s /e /q /r /y "%cd%\NX 10.0\UGSLicensing\nx_flex" "%AllUsersProfile%\nx_flex"
  9.     stsrt "" "%AllUsersProfile%\nx_flex\PLMstart.exe"
  10. )

  11. pause
复制代码
 楼主| 发表于 2015-6-23 07:48:08 | 显示全部楼层
文件属性 -> 详细信息 -> 文件版本
 楼主| 发表于 2015-6-23 07:57:04 | 显示全部楼层
本帖最后由 solan 于 2015-6-23 08:12 编辑

回复 7# terse
谢谢,终于有人来关心我了,非常感谢,不过你的代码不好使,没反应
注:那个stsrt写错了,可能你写快了吧
 楼主| 发表于 2015-6-23 08:05:05 | 显示全部楼层
pcl_test 老师,今在何处啊,你可要帮帮忙啊,麻烦您了,急啊
 楼主| 发表于 2015-6-23 09:40:39 | 显示全部楼层
本帖最后由 solan 于 2015-6-23 14:41 编辑

回复 7# terse

start "" "%AllUsersProfile%\nx_flex\PLMstart.exe"  你这样写好像也不行,没有前面的检查判断,如果重复启动PLMstart.exe的话,许可服务会冲突,软件没法用了
发表于 2015-6-23 10:34:13 | 显示全部楼层
回复 11# solan
你先试下能运行不 结果怎么样 或者有什么提示
 楼主| 发表于 2015-6-23 14:40:03 | 显示全部楼层
当ugslmd.exe在运行时,提示
请按任意键继续...

当ugslmd.exe没运行时,提示
No Instance Available
请按任意键继续...
发表于 2015-6-23 16:38:12 | 显示全部楼层
这样试试
  1. @echo off
  2. set w=wmic process where "name='ugslmd.exe'" get executablepath
  3. for /f "tokens=*" %%a in ('%w% 2^>nul ^| find ""') do set "ph=%%~dpa"
  4. if "%ph%" == "" echo,No Such Prosess&pause & exit/b

  5. set "dstFile=%ph%ugslmd.exe"
  6. set "srcFile=%~dp0NX 10.0\UGSLicensing\nx_flex\ugslmd.exe"

  7. >$ echo fso = new ActiveXObject("Scripting.FileSystemObject")
  8. >>$ echo v1 = fso.GetFileVersion("%dstFile:\=/%")
  9. >>$ echo v1 = v1.replace(/\d+/g,function(s0){return s0-0+100000000})
  10. >>$ echo v2 = fso.GetFileVersion("%srcFile:\=/%")
  11. >>$ echo v2 = v2.replace(/\d+/g,function(s0){return s0-0+100000000})
  12. >>$ echo WScript.Echo(v1 + " " + v2)

  13. for /f "tokens=1,2" %%1 in ('cscript -nologo -e:jscript $') do if "%%1" LSS "%%2" call :Next
  14. del $
  15. pause & exit/b

  16. :Next
  17. TASKKILL /F /IM lmgrdm.exe /T
  18. TASKKILL /F /IM lmgrd.exe /T
  19. move "%ph%ugslmd.exe" "%ph%ugslmd_bak.exe"
  20. rd /s /q "%AllUsersProfile%\nx_flex"
  21. xcopy /s /e /q /r /y "%~dp0NX 10.0\UGSLicensing\nx_flex\*" "%AllUsersProfile%\nx_flex"
  22. tasklist | findstr /ib "lmgrdm.exe" || "%AllUsersProfile%\nx_flex\PLMstart.exe"
复制代码

评分

参与人数 1技术 +1 收起 理由
solan + 1 感恩相助

查看全部评分

 楼主| 发表于 2015-6-23 17:50:03 | 显示全部楼层
回复 14# apang
谢谢,谢谢!在win7_64上测试通过,我就要这个效果
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-19 02:23 , Processed in 0.023475 second(s), 9 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表