[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[系统相关] [已解决]批处理获取操作系统和Office系列版本和位数

本帖最后由 pcl_test 于 2016-9-7 23:20 编辑

2012 R2上正常,XP在虚拟机试了一下貌似不对啊
  1. @echo off
  2. IF EXIST "%PROGRAMFILES(X86)%" (set ARCH=64BIT) ELSE (set ARCH=32BIT)
  3. ::echo %PROCESSOR_ARCHITECTURE%|findstr AMD64>nul && set ARCH=x64 || set ARCH=x86
  4. for /f "tokens=3*" %%A in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "ProductName"') do echo You are Running:%%A %%B %ARCH%
  5. pause
复制代码
2012 R2 输出:
You are Running:Windows Server 2012 R2 Datacenter 64BIT
请按任意键继续. . .

XP输出:
You are Running:VERSION 3.0 32BIT
You are Running:Microsoft Windows XP 32BIT
請按任意鍵繼續 . . .

哪里出问题了?谢谢
1

评分人数

    • Batcher: 感谢给帖子标题标注[已解决]字样PB + 2

回复 15# lantern


    昵称暴露驾龄

TOP

apang 发表于 2014-5-18 22:51
  1. Windows Registry Editor Version 5.00
  2. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{90160000-0011-0000-1000-0000000FF1CE}]
  3. "DisplayName"="Microsoft Office Professional Plus 2016"
复制代码
  1. @echo off & setlocal enabledelayedexpansion
  2. set "_00=32BIT Volume"
  3. set "_01=64BIT Volume"
  4. set "_10=32BIT Retail/OEM"
  5. set "_11=64BIT Retail/OEM"
  6. set "v=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
  7. set "re={9[01]160000-0011-0000-[01]000-0000000FF1CE}"
  8. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  9.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  10.         if /i "%%b" == "reg_sz" (
  11.             set "var=%%~nxa"
  12.             for %%d in ("!var:~2,1!!var:~20,1!") do echo,%%c !_%%~d!
  13.         )
  14.     )
  15. )) 2>nul
  16. if not defined var echo,Office 2013 Not Installed
  17. pause
复制代码
今天想试试office 2016,但运行后为何检测不到了?

TOP

回复 13# lantern


批处理for命令从入门到精通以及配套练习题
http://bbs.bathome.net/thread-2189-1-1.html
http://bbs.bathome.net/thread-2336-1-1.html

浅谈批处理命令for中的变量扩展
http://bbs.bathome.net/thread-2205-1-1.html
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

回复 12# apang
~nxa 这种哪里有教程吗,想看看?

TOP

本帖最后由 apang 于 2014-5-22 17:30 编辑

回复 11# lantern

    第一个for 得到的%%a值形如:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{90150000-0011-0000-0000-0000000FF1CE}
set "var=%%~nxa" 就是将 {90150000-0011-0000-0000-0000000FF1CE} 赋值给var
取var值第2位和20位(即00)
for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
也就是 for %%d in ("00") do echo; %%c !_%%~d!
变量 _00 前面已有定义,值为 32BIT Volume

TOP

本帖最后由 lantern 于 2014-5-22 06:03 编辑

回复 6# apang
  1. set "_00=32BIT Volume"
  2. set "_01=64BIT Volume"
  3. set "_10=32BIT Retail/OEM"
  4. set "_11=64BIT Retail/OEM"
  5. set "re={9[01]1[45]0000-0011-0000-[01]000-0000000FF1CE}"
  6. (for /f %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" ^| findstr /ie %re%') do (
  7.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  8.         if /i "%%b" == "REG_SZ" (
  9.             set "var=%%~nxa"
  10.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  11.         )
  12.     )
  13. )) 2>nul
复制代码
apang能不能讲解一下这段代码?set和最后一个for看不明白

TOP

回复  lantern
set "re={9[01]150000-0011-0000-[01]000-0000000FF1CE}" 改成 set "re={9[01]1[4 ...
apang 发表于 2014-5-19 11:32

多谢!这2段还能合并吗?...部分一样的
set "v=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
...
set "v=HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
...

后面Office激活的部分我先获取安装路径才执行,一般应该只存在一个%installroot%,是没有问题的,但是有可能2个或以上同时存在,该如何处理?
  1. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Office\14.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  2. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Office\15.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  3. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  4. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\15.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
复制代码
  1. @echo off
  2. title Microsoft Windows and Office Activate Helper
  3. setlocal enabledelayedexpansion
  4. :begin
  5. cls
  6. color 1F
  7. echo; -------=========Microsoft Windows and Office Activate Helper=========------
  8. echo;
  9. echo; THE FOLLOWING PRODUCTS CAN BE SUPPORTED:
  10. echo; Microsoft Windows Vista/7/8/8.1
  11. echo; Microsoft Windows Server 2008/2008R2/2012/2012R2
  12. echo; Microsoft Office/Project/Visio 2010/2013
  13. echo;
  14. echo; -------==========CURRENT OS OFFICE VISIO PROJECT VERSION==========---------
  15. echo;
  16. REM GET CURRENT OS VERSION
  17. if exist "%PROGRAMFILES(X86)%" (set arch=64BIT) else (set arch=32BIT)
  18. for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion"^|find /i "ProductName"') do (echo; %%j %arch%)
  19. REM GET CURRENT OFFICE VISIO PROJECT VERSION
  20. set "_00=32BIT Volume"
  21. set "_01=64BIT Volume"
  22. set "_10=32BIT Retail/OEM"
  23. set "_11=64BIT Retail/OEM"
  24. set "v=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
  25. set "re={9[01]1[45]0000-0012-0000-[01]000-0000000FF1CE}"
  26. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  27.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  28.         if /i "%%b" == "reg_sz" (
  29.             set "var=%%~nxa"
  30.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  31.         )
  32.     )
  33. )) 2>nul
  34. set "re={9[01]1[45]0000-0011-0000-[01]000-0000000FF1CE}"
  35. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  36.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  37.         if /i "%%b" == "reg_sz" (
  38.             set "var=%%~nxa"
  39.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  40.         )
  41.     )
  42. )) 2>nul
  43. set "re={9[01]1[45]0000-0051-0000-[01]000-0000000FF1CE}"
  44. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  45.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  46.         if /i "%%b" == "reg_sz" (
  47.             set "var=%%~nxa"
  48.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  49.         )
  50.     )
  51. )) 2>nul
  52. set "re={9[01]1[45]0000-0053-0000-[01]000-0000000FF1CE}"
  53. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  54.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  55.         if /i "%%b" == "reg_sz" (
  56.             set "var=%%~nxa"
  57.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  58.         )
  59.     )
  60. )) 2>nul
  61. set "re={9[01]1[45]0000-0057-0000-[01]000-0000000FF1CE}"
  62. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  63.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  64.         if /i "%%b" == "reg_sz" (
  65.             set "var=%%~nxa"
  66.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  67.         )
  68.     )
  69. )) 2>nul
  70. set "re={9[01]1[45]0000-003A-0000-[01]000-0000000FF1CE}"
  71. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  72.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  73.         if /i "%%b" == "reg_sz" (
  74.             set "var=%%~nxa"
  75.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  76.         )
  77.     )
  78. )) 2>nul
  79. set "re={9[01]1[45]0000-003B-0000-[01]000-0000000FF1CE}"
  80. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  81.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  82.         if /i "%%b" == "reg_sz" (
  83.             set "var=%%~nxa"
  84.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  85.         )
  86.     )
  87. )) 2>nul
  88. set "v=HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
  89. set "re={9[01]1[45]0000-0012-0000-[01]000-0000000FF1CE}"
  90. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  91.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  92.         if /i "%%b" == "reg_sz" (
  93.             set "var=%%~nxa"
  94.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  95.         )
  96.     )
  97. )) 2>nul
  98. set "re={9[01]1[45]0000-0011-0000-[01]000-0000000FF1CE}"
  99. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  100.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  101.         if /i "%%b" == "reg_sz" (
  102.             set "var=%%~nxa"
  103.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  104.         )
  105.     )
  106. )) 2>nul
  107. set "re={9[01]1[45]0000-0051-0000-[01]000-0000000FF1CE}"
  108. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  109.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  110.         if /i "%%b" == "reg_sz" (
  111.             set "var=%%~nxa"
  112.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  113.         )
  114.     )
  115. )) 2>nul
  116. set "re={9[01]1[45]0000-0053-0000-[01]000-0000000FF1CE}"
  117. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  118.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  119.         if /i "%%b" == "reg_sz" (
  120.             set "var=%%~nxa"
  121.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  122.         )
  123.     )
  124. )) 2>nul
  125. set "re={9[01]1[45]0000-0057-0000-[01]000-0000000FF1CE}"
  126. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  127.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  128.         if /i "%%b" == "reg_sz" (
  129.             set "var=%%~nxa"
  130.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  131.         )
  132.     )
  133. )) 2>nul
  134. set "re={9[01]1[45]0000-003A-0000-[01]000-0000000FF1CE}"
  135. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  136.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  137.         if /i "%%b" == "reg_sz" (
  138.             set "var=%%~nxa"
  139.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  140.         )
  141.     )
  142. )) 2>nul
  143. set "re={9[01]1[45]0000-003B-0000-[01]000-0000000FF1CE}"
  144. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  145.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  146.         if /i "%%b" == "reg_sz" (
  147.             set "var=%%~nxa"
  148.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  149.         )
  150.     )
  151. )) 2>nul
  152. echo; ---------=========================================================---------
  153. echo;
  154. echo; 1.Online Activate Microsoft Windows
  155. echo;
  156. echo; 2.Online Activate Microsoft Office
  157. echo;
  158. echo; 3.Offline Activate Microsoft Windows
  159. echo;
  160. echo; 4.Offline Activate Microsoft Office
  161. echo;
  162. set /p ans=PLEASE CHOOSE 1/2/3/4 AND PRESS ENTER TO CONTINUE:
  163. if "%ans%"=="1" goto onlinewindows
  164. if "%ans%"=="2" goto onlineoffice
  165. if "%ans%"=="3" goto offlinewindows
  166. if "%ans%"=="4" goto offlineoffice
  167. goto begin
  168. REM Online Activate Microsoft Windows
  169. :onlinewindows
  170. goto inputkey
  171. :inputkey
  172. cls
  173. set /p inputkey=PLEASE ENTER PRODUCT KEY LIKE XXXXX-XXXXX-XXXXX-XXXXX-XXXXX AND PRESS ENTER TO CONTINUE:
  174. cscript /nologo %windir%\system32\slmgr.vbs /ipk %inputkey% | findstr /x "成功地安装了产品密钥" >nul && goto ato || goto reenter
  175. :ato
  176. cls
  177. cscript /nologo %windir%\system32\slmgr.vbs /ato | findstr /x "成功地激活了产品" >nul && goto done || goto reenter
  178. :done
  179. cls
  180. echo;ACTIVATION SUCCESSFUL!
  181. timeout 5
  182. goto begin
  183. :reenter
  184. cls
  185. echo;密钥无效,请更换密钥重新输入
  186. timeout 5
  187. goto inputkey
  188. REM Offline Activate Microsoft Windows
  189. :offlinewindows
  190. goto inputkeyb
  191. :inputkeyb
  192. cls
  193. set /p inputkeyb=PLEASE ENTER PRODUCT KEY LIKE XXXXX-XXXXX-XXXXX-XXXXX-XXXXX AND PRESS ENTER TO CONTINUE:
  194. cscript /nologo %windir%\system32\slmgr.vbs /ipk %inputkeyb% | findstr /x "成功地安装了产品密钥" >nul && goto atob || goto reenter
  195. :atob
  196. cls
  197. echo;免费、无广告、无需注册、不限时间、不限流量VPN:http://tenacy-free.com/
  198. echo;
  199. echo;VPN使用教程:http://tenacy-free.com/tutorials/pptp-windows-8
  200. echo;
  201. echo;Skype下载:http://www.skype.com/go/getskype-msi
  202. echo;
  203. echo;英国电话号码:8000188354
  204. echo;
  205. echo;语音翻译:http://www.lenovo.me/wp-content/uploads/englishtochinese.txt
  206. echo;
  207. cscript /nologo %windir%\system32\slmgr.vbs /dti >dti.txt
  208. echo;安装ID(9组×7位,共63位)已保存在当前目录dti.txt文件中
  209. echo;
  210. echo;请挂VPN用Skype打英国电话,记下确认ID
  211. echo;
  212. echo; a.密钥无效(无法获得确认ID)
  213. echo;
  214. echo; b.密钥有效(已经获得确认ID)
  215. echo;
  216. set /p ab=请输入字母a or b后按Enter键继续:
  217. if "%ab%"=="a" goto inputkeyb
  218. if "%ab%"=="b" goto atoc
  219. :atoc
  220. cls
  221. set /p wcid=请输入确认ID(8组×6位,共48位,连续输入,不用输-):
  222. cscript /nologo %windir%\system32\slmgr.vbs /atp %wcid% | findstr /x "确认 ID 成功地存储" >nul && goto done || goto reenter
  223. REM Online Activate Microsoft Office
  224. :onlineoffice
  225. goto ipk
  226. :ipk
  227. cls
  228. set /p ipk=PLEASE ENTER PRODUCT KEY LIKE XXXXX-XXXXX-XXXXX-XXXXX-XXXXX AND PRESS ENTER TO CONTINUE:
  229. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Office\14.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  230. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Office\15.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  231. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  232. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\15.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  233. cscript "%installroot%\ospp.vbs" /inpkey:%ipk% | findstr /x "<Product key installation successful>" >nul && goto act || goto reenterb
  234. :act
  235. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Office\14.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  236. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Office\15.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  237. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  238. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\15.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  239. cscript "%installroot%\ospp.vbs" /act | findstr /x "<Product activation successful>" >nul && goto done || goto reenterb
  240. :reenterb
  241. cls
  242. echo;密钥无效,请更换密钥重新输入
  243. timeout 5
  244. goto ipk
  245. REM Offline Activate Microsoft Office
  246. :offlineoffice
  247. goto ipkb
  248. :ipkb
  249. cls
  250. set /p ipk=PLEASE ENTER PRODUCT KEY LIKE XXXXX-XXXXX-XXXXX-XXXXX-XXXXX AND PRESS ENTER TO CONTINUE:
  251. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Office\14.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  252. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Office\15.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  253. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  254. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\15.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  255. cscript "%installroot%\ospp.vbs" /inpkey:%ipk% | findstr /x "<Product key installation successful>" >nul && goto actb || goto reenterb
  256. :actb
  257. cls
  258. echo;免费、无广告、无需注册、不限时间、不限流量VPN:http://tenacy-free.com/
  259. echo;
  260. echo;VPN使用教程:http://tenacy-free.com/tutorials/pptp-windows-8
  261. echo;
  262. echo;Skype下载:http://www.skype.com/go/getskype-msi
  263. echo;
  264. echo;英国电话号码:8000188354
  265. echo;
  266. echo;语音翻译:http://www.lenovo.me/wp-content/uploads/englishtochinese.txt
  267. echo;
  268. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Office\14.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  269. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Office\15.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  270. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  271. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\15.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  272. cscript "%installroot%\ospp.vbs" /dinstid >dinstid.txt
  273. echo;安装ID(9组×7位,共63位)已保存在当前目录dinstid.txt文件中
  274. echo;
  275. echo;请挂VPN用Skype打英国电话,记下确认ID
  276. echo;
  277. echo; a.密钥无效(无法获得确认ID)
  278. echo;
  279. echo; b.密钥有效(已经获得确认ID)
  280. echo;
  281. set /p ab=请输入字母a or b后按Enter键继续:
  282. if "%ab%"=="a" goto ipkb
  283. if "%ab%"=="b" goto actc
  284. :actc
  285. cls
  286. set /p ocid=请输入确认ID(8组×6位,共48位,连续输入,不用输-):
  287. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Office\14.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  288. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Office\15.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  289. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  290. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\15.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  291. cscript "%installroot%\ospp.vbs" /actcid:%ocid% | findstr /x "<Offline product activation successful>" >nul && goto done || goto reenterb
复制代码

TOP

回复 7# lantern


    set "re={9[01]150000-0011-0000-[01]000-0000000FF1CE}" 改成 set "re={9[01]1[45]0000-00..-0000-[01]000-0000000FF1CE}"
可以精简掉很多重复性代码
运行ospp.vbs的代码似乎可以这样:
  1. @echo off & setlocal enabledelayedexpansion
  2. set "file=%ProgramFiles%\MICROSOFT OFFICE\OFFICE15\OSPP.VBS"
  3. for /f "delims=" %%a in ('cscript -nologo "%file%"') do (
  4.     set "str=%%a"
  5.     if defined flag (
  6.         if "!str:NAME:=!" neq "!str!" (
  7.             set "Name=!str:*NAME:=!"
  8.         ) else if "!str:STATUS:=!" neq "!str!" (
  9.             echo,!Name! !str:*STATUS:=!
  10.             set "flag="
  11.         )
  12.     ) else if "!str:-=!"=="" set flag=1
  13. )
  14. pause
复制代码
1

评分人数

TOP

本帖最后由 lantern 于 2014-5-19 07:04 编辑

还有个需求:如何判断Office/Project/Visio是否已经激活?也想整合到前面代码中去
只装了三者之一的话,findstr查找LICENSED就行,但是装了三者之二、之三的话,如何区分LICENSED分别对应那个产品呢?谢谢
KMS激活的和下面的输出不一样,但是都是---------------------------------------隔开的,这个能帮助分块提取产品名称和LICENSED吗?
  1. Microsoft Windows [版本 6.3.9600]
  2. (c) 2013 Microsoft Corporation。保留所有权利。
  3. C:\Windows\system32>CD "%ProgramFiles%\MICROSOFT OFFICE\OFFICE15"
  4. C:\Program Files\Microsoft Office\Office15>CSCRIPT OSPP.VBS /DSTATUS
  5. Microsoft (R) Windows Script Host Version 5.8
  6. 版权所有(C) Microsoft Corporation。保留所有权利。
  7. ---Processing--------------------------
  8. ---------------------------------------
  9. SKU ID: 2b88c4f2-ea8f-43cd-805e-4d41346e18a7
  10. LICENSE NAME: Office 15, OfficeProPlusVL_MAK edition
  11. LICENSE DESCRIPTION: Office 15, RETAIL(MAK) channel
  12. LICENSE STATUS:  ---LICENSED---
  13. Last 5 characters of installed product key: 2YQ67
  14. ---------------------------------------
  15. SKU ID: 3e4294dd-a765-49bc-8dbd-cf8b62a4bd3d
  16. LICENSE NAME: Office 15, OfficeVisioProVL_MAK edition
  17. LICENSE DESCRIPTION: Office 15, RETAIL(MAK) channel
  18. LICENSE STATUS:  ---LICENSED---
  19. Last 5 characters of installed product key: RM3B4
  20. ---------------------------------------
  21. SKU ID: ed34dc89-1c27-4ecd-8b2f-63d0f4cedc32
  22. LICENSE NAME: Office 15, OfficeProjectProVL_MAK edition
  23. LICENSE DESCRIPTION: Office 15, RETAIL(MAK) channel
  24. LICENSE STATUS:  ---LICENSED---
  25. Last 5 characters of installed product key: RVR2M
  26. ---------------------------------------
  27. ---------------------------------------
  28. ---Exiting-----------------------------
  29. C:\Program Files\Microsoft Office\Office15>
复制代码

TOP

apang 发表于 2014-5-18 22:51


多谢!暂且弄成这样了
Office/Project/Visio 2010/2013的版本获取真麻烦,情况太多了:
32位Office/Project/Visio 2010/2013 安装在32位系统中
32位Office/Project/Visio 2010/2013 安装在64位系统中
64位Office/Project/Visio 2010/2013 安装在64位系统中
还有同时装了2010和2013版本....
  1. @echo off
  2. title Microsoft Windows and Office Activate Helper
  3. setlocal enabledelayedexpansion
  4. :begin
  5. cls
  6. color 1F
  7. echo; -------=========Microsoft Windows and Office Activate Helper=========------
  8. echo;
  9. echo; THE FOLLOWING PRODUCTS CAN BE SUPPORTED:
  10. echo; Microsoft Windows Vista/7/8/8.1
  11. echo; Microsoft Windows Server 2008/2008R2/2012/2012R2
  12. echo; Microsoft Office/Project/Visio 2010/2013
  13. echo;
  14. echo; -------==========CURRENT OS OFFICE VISIO PROJECT VERSION==========---------
  15. echo;
  16. REM GET CURRENT OS VERSION
  17. IF EXIST "%PROGRAMFILES(X86)%" (set ARCH=64BIT) ELSE (set ARCH=32BIT)
  18. for /f "tokens=2*" %%A in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion"^|find /i "ProductName"') do (echo; %%B %ARCH%)
  19. REM GET CURRENT OFFICE VISIO PROJECT VERSION
  20. set "_00=32BIT Volume"
  21. set "_01=64BIT Volume"
  22. set "_10=32BIT Retail/OEM"
  23. set "_11=64BIT Retail/OEM"
  24. set "v=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
  25. set "re={9[01]140000-0012-0000-[01]000-0000000FF1CE}"
  26. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  27.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  28.         if /i "%%b" == "reg_sz" (
  29.             set "var=%%~nxa"
  30.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  31.         )
  32.     )
  33. )) 2>nul
  34. set "re={9[01]140000-0011-0000-[01]000-0000000FF1CE}"
  35. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  36.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  37.         if /i "%%b" == "reg_sz" (
  38.             set "var=%%~nxa"
  39.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  40.         )
  41.     )
  42. )) 2>nul
  43. set "re={9[01]140000-0053-0000-[01]000-0000000FF1CE}"
  44. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  45.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  46.         if /i "%%b" == "reg_sz" (
  47.             set "var=%%~nxa"
  48.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  49.         )
  50.     )
  51. )) 2>nul
  52. set "re={9[01]140000-0057-0000-[01]000-0000000FF1CE}"
  53. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  54.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  55.         if /i "%%b" == "reg_sz" (
  56.             set "var=%%~nxa"
  57.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  58.         )
  59.     )
  60. )) 2>nul
  61. set "re={9[01]140000-003A-0000-[01]000-0000000FF1CE}"
  62. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  63.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  64.         if /i "%%b" == "reg_sz" (
  65.             set "var=%%~nxa"
  66.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  67.         )
  68.     )
  69. )) 2>nul
  70. set "re={9[01]140000-003B-0000-[01]000-0000000FF1CE}"
  71. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  72.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  73.         if /i "%%b" == "reg_sz" (
  74.             set "var=%%~nxa"
  75.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  76.         )
  77.     )
  78. )) 2>nul
  79. set "re={9[01]150000-0012-0000-[01]000-0000000FF1CE}"
  80. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  81.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  82.         if /i "%%b" == "reg_sz" (
  83.             set "var=%%~nxa"
  84.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  85.         )
  86.     )
  87. )) 2>nul
  88. set "re={9[01]150000-0011-0000-[01]000-0000000FF1CE}"
  89. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  90.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  91.         if /i "%%b" == "reg_sz" (
  92.             set "var=%%~nxa"
  93.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  94.         )
  95.     )
  96. )) 2>nul
  97. set "re={9[01]150000-0053-0000-[01]000-0000000FF1CE}"
  98. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  99.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  100.         if /i "%%b" == "reg_sz" (
  101.             set "var=%%~nxa"
  102.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  103.         )
  104.     )
  105. )) 2>nul
  106. set "re={9[01]150000-0051-0000-[01]000-0000000FF1CE}"
  107. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  108.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  109.         if /i "%%b" == "reg_sz" (
  110.             set "var=%%~nxa"
  111.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  112.         )
  113.     )
  114. )) 2>nul
  115. set "re={9[01]150000-003A-0000-[01]000-0000000FF1CE}"
  116. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  117.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  118.         if /i "%%b" == "reg_sz" (
  119.             set "var=%%~nxa"
  120.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  121.         )
  122.     )
  123. )) 2>nul
  124. set "re={9[01]150000-003B-0000-[01]000-0000000FF1CE}"
  125. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  126.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  127.         if /i "%%b" == "reg_sz" (
  128.             set "var=%%~nxa"
  129.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  130.         )
  131.     )
  132. )) 2>nul
  133. set "v=HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
  134. set "re={9[01]140000-0012-0000-[01]000-0000000FF1CE}"
  135. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  136.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  137.         if /i "%%b" == "reg_sz" (
  138.             set "var=%%~nxa"
  139.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  140.         )
  141.     )
  142. )) 2>nul
  143. set "re={9[01]140000-0011-0000-[01]000-0000000FF1CE}"
  144. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  145.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  146.         if /i "%%b" == "reg_sz" (
  147.             set "var=%%~nxa"
  148.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  149.         )
  150.     )
  151. )) 2>nul
  152. set "re={9[01]140000-0053-0000-[01]000-0000000FF1CE}"
  153. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  154.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  155.         if /i "%%b" == "reg_sz" (
  156.             set "var=%%~nxa"
  157.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  158.         )
  159.     )
  160. )) 2>nul
  161. set "re={9[01]140000-0057-0000-[01]000-0000000FF1CE}"
  162. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  163.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  164.         if /i "%%b" == "reg_sz" (
  165.             set "var=%%~nxa"
  166.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  167.         )
  168.     )
  169. )) 2>nul
  170. set "re={9[01]140000-003A-0000-[01]000-0000000FF1CE}"
  171. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  172.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  173.         if /i "%%b" == "reg_sz" (
  174.             set "var=%%~nxa"
  175.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  176.         )
  177.     )
  178. )) 2>nul
  179. set "re={9[01]140000-003B-0000-[01]000-0000000FF1CE}"
  180. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  181.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  182.         if /i "%%b" == "reg_sz" (
  183.             set "var=%%~nxa"
  184.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  185.         )
  186.     )
  187. )) 2>nul
  188. set "re={9[01]150000-0012-0000-[01]000-0000000FF1CE}"
  189. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  190.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  191.         if /i "%%b" == "reg_sz" (
  192.             set "var=%%~nxa"
  193.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  194.         )
  195.     )
  196. )) 2>nul
  197. set "re={9[01]150000-0011-0000-[01]000-0000000FF1CE}"
  198. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  199.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  200.         if /i "%%b" == "reg_sz" (
  201.             set "var=%%~nxa"
  202.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  203.         )
  204.     )
  205. )) 2>nul
  206. set "re={9[01]150000-0053-0000-[01]000-0000000FF1CE}"
  207. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  208.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  209.         if /i "%%b" == "reg_sz" (
  210.             set "var=%%~nxa"
  211.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  212.         )
  213.     )
  214. )) 2>nul
  215. set "re={9[01]150000-0051-0000-[01]000-0000000FF1CE}"
  216. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  217.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  218.         if /i "%%b" == "reg_sz" (
  219.             set "var=%%~nxa"
  220.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  221.         )
  222.     )
  223. )) 2>nul
  224. set "re={9[01]150000-003A-0000-[01]000-0000000FF1CE}"
  225. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  226.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  227.         if /i "%%b" == "reg_sz" (
  228.             set "var=%%~nxa"
  229.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  230.         )
  231.     )
  232. )) 2>nul
  233. set "re={9[01]150000-003B-0000-[01]000-0000000FF1CE}"
  234. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  235.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  236.         if /i "%%b" == "reg_sz" (
  237.             set "var=%%~nxa"
  238.             for %%d in ("!var:~2,1!!var:~20,1!") do echo; %%c !_%%~d!
  239.         )
  240.     )
  241. )) 2>nul
  242. echo; ---------=========================================================---------
  243. echo;
  244. echo; 1.Online Activate Microsoft Windows
  245. echo;
  246. echo; 2.Online Activate Microsoft Office
  247. echo;
  248. echo; 3.Offline Activate Microsoft Windows
  249. echo;
  250. echo; 4.Offline Activate Microsoft Office
  251. echo;
  252. set /p ans=PLEASE CHOOSE 1/2/3/4 AND PRESS ENTER TO CONTINUE:
  253. if "%ans%"=="1" goto onlinewindows
  254. if "%ans%"=="2" goto onlineoffice
  255. if "%ans%"=="3" goto offlinewindows
  256. if "%ans%"=="4" goto offlineoffice
  257. goto begin
  258. REM Online Activate Microsoft Windows
  259. :onlinewindows
  260. goto inputkey
  261. :inputkey
  262. cls
  263. set /p inputkey=PLEASE ENTER PRODUCT KEY LIKE XXXXX-XXXXX-XXXXX-XXXXX-XXXXX AND PRESS ENTER TO CONTINUE:
  264. cscript /nologo %windir%\system32\slmgr.vbs /ipk %inputkey% | findstr 成功地安装了产品密钥 >nul && goto ato || goto reenter
  265. :ato
  266. cls
  267. cscript /nologo %windir%\system32\slmgr.vbs /ato | findstr 成功地激活了产品 >nul && goto done || goto reenter
  268. :done
  269. cls
  270. echo;已成功激活
  271. timeout 5
  272. goto begin
  273. :reenter
  274. cls
  275. echo;密钥无效,请更换密钥重新输入
  276. timeout 5
  277. goto inputkey
  278. REM Offline Activate Microsoft Windows
  279. :offlinewindows
  280. goto inputkeyb
  281. :inputkeyb
  282. cls
  283. set /p inputkeyb=PLEASE ENTER PRODUCT KEY LIKE XXXXX-XXXXX-XXXXX-XXXXX-XXXXX AND PRESS ENTER TO CONTINUE:
  284. cscript /nologo %windir%\system32\slmgr.vbs /ipk %inputkeyb% | findstr 成功地安装了产品密钥 >nul && goto atob || goto reenter
  285. :atob
  286. cls
  287. echo;免费、无广告、无需注册、不限时间、不限流量VPN:http://tenacy-free.com/
  288. echo;
  289. echo;VPN使用教程:http://tenacy-free.com/tutorials/pptp-windows-8
  290. echo;
  291. echo;Skype下载:http://www.skype.com/go/getskype-msi
  292. echo;
  293. echo;英国电话号码:8000188354
  294. echo;
  295. echo;语音翻译:http://www.lenovo.me/wp-content/uploads/englishtochinese.txt
  296. echo;
  297. cscript /nologo %windir%\system32\slmgr.vbs /dti >dti.txt
  298. echo;安装ID(9组×7位,共63位)已保存在当前目录dti.txt文件中
  299. echo;
  300. echo;请挂VPN用Skype打英国电话,记下确认ID
  301. echo;
  302. echo; a.密钥无效(无法获得确认ID)
  303. echo;
  304. echo; b.密钥有效(已经获得确认ID)
  305. echo;
  306. set /p ab=请输入字母a or b后按Enter键继续:
  307. if "%ab%"=="a" goto inputkeyb
  308. if "%ab%"=="b" goto atoc
  309. :atoc
  310. cls
  311. set /p wcid=请输入确认ID(8组×6位,共48位,连续输入,不用输-):
  312. cscript /nologo %windir%\system32\slmgr.vbs /atp %wcid% | findstr /x "确认 ID 成功地存储" >nul && goto done || goto reenter
  313. REM Online Activate Microsoft Office
  314. :onlineoffice
  315. goto ipk
  316. :ipk
  317. cls
  318. set /p ipk=PLEASE ENTER PRODUCT KEY LIKE XXXXX-XXXXX-XXXXX-XXXXX-XXXXX AND PRESS ENTER TO CONTINUE:
  319. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Office\14.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  320. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Office\15.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  321. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  322. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\15.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  323. cscript "%installroot%\ospp.vbs" /inpkey:%ipk% | findstr /x "<Product key installation successful>" >nul && goto act || goto reenterb
  324. :act
  325. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Office\14.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  326. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Office\15.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  327. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  328. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\15.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  329. cscript "%installroot%\ospp.vbs" /act | findstr /x "<Product activation successful>" >nul && goto done || goto reenterb
  330. :reenterb
  331. cls
  332. echo;密钥无效,请更换密钥重新输入
  333. timeout 5
  334. goto ipk
  335. REM Offline Activate Microsoft Office
  336. :offlineoffice
  337. goto ipkb
  338. :ipkb
  339. cls
  340. set /p ipk=PLEASE ENTER PRODUCT KEY LIKE XXXXX-XXXXX-XXXXX-XXXXX-XXXXX AND PRESS ENTER TO CONTINUE:
  341. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Office\14.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  342. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Office\15.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  343. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  344. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\15.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  345. cscript "%installroot%\ospp.vbs" /inpkey:%ipk% | findstr /x "<Product key installation successful>" >nul && goto actb || goto reenterb
  346. :actb
  347. cls
  348. echo;免费、无广告、无需注册、不限时间、不限流量VPN:http://tenacy-free.com/
  349. echo;
  350. echo;VPN使用教程:http://tenacy-free.com/tutorials/pptp-windows-8
  351. echo;
  352. echo;Skype下载:http://www.skype.com/go/getskype-msi
  353. echo;
  354. echo;英国电话号码:8000188354
  355. echo;
  356. echo;语音翻译:http://www.lenovo.me/wp-content/uploads/englishtochinese.txt
  357. echo;
  358. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Office\14.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  359. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Office\15.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  360. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  361. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\15.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  362. cscript "%installroot%\ospp.vbs" /dinstid >dinstid.txt
  363. echo;安装ID(9组×7位,共63位)已保存在当前目录dinstid.txt文件中
  364. echo;
  365. echo;请挂VPN用Skype打英国电话,记下确认ID
  366. echo;
  367. echo; a.密钥无效(无法获得确认ID)
  368. echo;
  369. echo; b.密钥有效(已经获得确认ID)
  370. echo;
  371. set /p ab=请输入字母a or b后按Enter键继续:
  372. if "%ab%"=="a" goto ipkb
  373. if "%ab%"=="b" goto actc
  374. :actc
  375. cls
  376. set /p ocid=请输入确认ID(8组×6位,共48位,连续输入,不用输-):
  377. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Office\14.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  378. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Office\15.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  379. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  380. (for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\15.0\Common\InstallRoot"^| find /i "Path"') do (set installroot=%%j))2>nul
  381. cscript "%installroot%\ospp.vbs" /actcid:%ocid% | findstr /x "<Offline product activation successful>" >nul && goto done || goto reenterb
复制代码

TOP

  1. @echo off & setlocal enabledelayedexpansion
  2. set "_00=32BIT Volume"
  3. set "_01=64BIT Volume"
  4. set "_10=32BIT Retail/OEM"
  5. set "_11=64BIT Retail/OEM"
  6. set "v=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
  7. set "re={9[01]150000-0011-0000-[01]000-0000000FF1CE}"
  8. (for /f "delims=" %%a in ('reg query "%v%" ^| findstr /ie %re%') do (
  9.     for /f "tokens=2*" %%b in ('reg query "%%a" /v "DisplayName"') do (
  10.         if /i "%%b" == "reg_sz" (
  11.             set "var=%%~nxa"
  12.             for %%d in ("!var:~2,1!!var:~20,1!") do echo,%%c !_%%~d!
  13.         )
  14.     )
  15. )) 2>nul
  16. if not defined var echo,Office 2013 Not Installed
  17. pause
复制代码

TOP

本帖最后由 lantern 于 2014-5-18 22:41 编辑

又改了一下,输出:
错误: 系统找不到指定的注册表项或值。
错误: 系统找不到指定的注册表项或值。
错误: 系统找不到指定的注册表项或值。
错误: 系统找不到指定的注册表项或值。
您当前的Office版本是: 64BIT Volume
错误: 系统找不到指定的注册表项或值。
错误: 系统找不到指定的注册表项或值。
错误: 系统找不到指定的注册表项或值。
错误: 系统找不到指定的注册表项或值。
您当前的Office版本是: 64BIT Volume
错误: 系统找不到指定的注册表项或值。
错误: 系统找不到指定的注册表项或值。
错误: 系统找不到指定的注册表项或值。
您当前的Office版本是:Microsoft Office Professional Plus 2013 64BIT Volume
错误: 系统找不到指定的注册表项或值。
错误: 系统找不到指定的注册表项或值。
错误: 系统找不到指定的注册表项或值。
错误: 系统找不到指定的注册表项或值。
您当前的Office版本是:Microsoft Office Professional Plus 2013 64BIT Volume
请按任意键继续. . .

我想到最后要么输出:您没有安装Microsoft Office,要么输出正确的office版本,怎么修改才能做到?谢谢
  1. @echo off
  2. ::setlocal enabledelayedexpansion
  3. rem 获取当前的Office版本
  4. rem 90(1)140000-0011-0000-0(1)000-0000000FF1CE Microsoft Office Professional Plus 2010
  5. for %%a in (0,1) do (
  6. for %%b in (1,0) do (
  7. for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{9%%b140000-0011-0000-%%a000-0000000FF1CE}"^|find /i
  8. "DisplayName"') do (
  9. set name=%%j
  10. )
  11. if %%a==1 (
  12. if %%b==0 (
  13. set edition=Volume
  14. ) else (
  15. set edition=Retail/OEM
  16. )
  17. set arch=64BIT
  18. ) else (
  19. if %%b==0 (
  20. set edition=Volume
  21. ) else (
  22. set edition=Retail/OEM
  23. )
  24. set arch=32BIT
  25. )
  26. )
  27. )
  28. echo; 您当前的Office版本是:%name% %arch% %edition%
  29. rem 90(1)140000-0012-0000-0(1)000-0000000FF1CE Microsoft Office Standard 2010
  30. for %%a in (0,1) do (
  31. for %%b in (1,0) do (
  32. for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{9%%b140000-0012-0000-%%a000-0000000FF1CE}"^|find /i
  33. "DisplayName"') do (
  34. set name=%%j
  35. )
  36. if %%a==1 (
  37. if %%b==0 (
  38. set edition=Volume
  39. ) else (
  40. set edition=Retail/OEM
  41. )
  42. set arch=64BIT
  43. ) else (
  44. if %%b==0 (
  45. set edition=Volume
  46. ) else (
  47. set edition=Retail/OEM
  48. )
  49. set arch=32BIT
  50. )
  51. )
  52. )
  53. echo; 您当前的Office版本是:%name% %arch% %edition%
  54. rem 90(1)150000-0011-0000-0(1)000-0000000FF1CE Microsoft Office Professional Plus 2013
  55. for %%a in (0,1) do (
  56. for %%b in (1,0) do (
  57. for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{9%%b150000-0011-0000-%%a000-0000000FF1CE}"^|find /i "DisplayName"') do (
  58. set name=%%j
  59. )
  60. if %%a==1 (
  61. if %%b==0 (
  62. set edition=Volume
  63. ) else (
  64. set edition=Retail/OEM
  65. )
  66. set arch=64BIT
  67. ) else (
  68. if %%b==0 (
  69. set edition=Volume
  70. ) else (
  71. set edition=Retail/OEM
  72. )
  73. set arch=32BIT
  74. )
  75. )
  76. )
  77. echo; 您当前的Office版本是:%name% %arch% %edition%
  78. rem 90(1)150000-0012-0000-0(1)000-0000000FF1CE Microsoft Office Standard 2013
  79. for %%a in (0,1) do (
  80. for %%b in (1,0) do (
  81. for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{9%%b150000-0012-0000-%%a000-0000000FF1CE}"^|find /i "DisplayName"') do (
  82. set name=%%j
  83. )
  84. if %%a==1 (
  85. if %%b==0 (
  86. set edition=Volume
  87. ) else (
  88. set edition=Retail/OEM
  89. )
  90. set arch=64BIT
  91. ) else (
  92. if %%b==0 (
  93. set edition=Volume
  94. ) else (
  95. set edition=Retail/OEM
  96. )
  97. set arch=32BIT
  98. )
  99. )
  100. )
  101. echo; 您当前的Office版本是:%name% %arch% %edition%
  102. pause
复制代码

TOP

本帖最后由 lantern 于 2014-5-18 17:36 编辑

回复 3# apang
谢谢!参考这个又写了一段判断Office版本和BIT的,怎么把错误信息过滤掉?
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. for /l %%a in (0,1,1) do (
  4. for /l %%b in (0,1,1) do (
  5. for /f "tokens=2*" %%i in ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{9%%b150000-0011-0000-%%a000-0000000FF1CE}"^|find /i "DisplayName"') do (
  6. set name=%%j
  7. )
  8. if %%a==1 (
  9. set arch=64BIT
  10. ) else (
  11. set arch=32BIT
  12. )
  13. if %%b==0 (
  14. set edition=Volume
  15. ) else (
  16. set edition=Retail/OEM
  17. )
  18. )
  19. )
  20. echo %name% %arch% %edition%
  21. pause
复制代码
现在输出是:
错误: 系统找不到指定的注册表项或值。
错误: 系统找不到指定的注册表项或值。
错误: 系统找不到指定的注册表项或值。
Microsoft Office Professional Plus 2013 64BIT Retail/OEM
请按任意键继续. . .

我只想要最后一行...

另外逻辑上是不是不对啊?我是Volume版本的,输出是Retail/OEM
正确的对应关系是
90150000-0011-0000-0000-0000000FF1CE Microsoft Office Professional Plus 2013 32BIT Volume
90150000-0011-0000-1000-0000000FF1CE Microsoft Office Professional Plus 2013 64BIT Volume
91150000-0011-0000-0000-0000000FF1CE Microsoft Office Professional Plus 2013 32BIT Retail/OEM
91150000-0011-0000-1000-0000000FF1CE Microsoft Office Professional Plus 2013 64BIT Retail/OEM

TOP

XP 的reg query 会自动加上一行reg自身的版本号:! reg.exe Version 3.0
  1. for /f "tokens=2*" %%A in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion"^|find /i "ProductName"') do (
  2.     echo You are Running:%%B %ARCH%
  3. )
复制代码
或者
  1. for /f "tokens=2*" %%A in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "ProductName"') do (
  2.     if /i "%%A" == "REG_SZ" echo You are Running:%%B %ARCH%
  3. )
复制代码

TOP

返回列表