setdesktop.bat 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. @echo off
  2. @setlocal enabledelayedexpansion
  3. @set CurrentDir=%~dp0
  4. @cd /d %CurrentDir%
  5. @set ROOT=%cd%
  6. @set ret=-1
  7. @set errmsg=all process has been executed succ
  8. @set resultFile=%CurrentDir%result.log
  9. @set tmpLogFile=D:\\test.txt
  10. @set supportBS=1
  11. @echo result=-1^&msg=install begin >%resultFile%
  12. @echo [RVCTermianal] ========== Install Start ==========
  13. @echo %date:~0,4%-%date:~5,2%-%date:~8,2% %time:~0,2%:%time:~3,2%:%time:~6,2%
  14. @echo Current Dir: %CurrentDir%
  15. @echo ROOT Dir: %ROOT%
  16. ::rem get os bit
  17. reg query HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0 /v "Identifier" | find "64 Family" >NUL 2>nul && set OS=64BIT || set OS=32BIT
  18. if %OS%==32BIT (
  19. @echo [DEBUg] x86 platform
  20. ) else (
  21. @echo [DEBUg] x64 platform
  22. )
  23. @rem 操作系统版本
  24. @rem 10: Win10
  25. @rem 8: Win8
  26. @set SystermVer=0
  27. @set regKey=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
  28. @set regValue=ProductName
  29. @set regData=
  30. for /f "tokens=2*" %%a in ('reg query "%regKey%" /v "%regValue%" ^| findstr /i "%regValue%"') do (
  31. set regData=%%b
  32. )
  33. @echo [DEBUG] The value of %regValue% is: %regData%
  34. @if "%regData%" == "" (
  35. set supportBS=0
  36. echo [DEBUG] to get ProductName twice
  37. for /f "tokens=2*" %%a in ('reg query "\"%regKey%\"" /v "%regValue%" ^| findstr /i "%regValue%"') do (
  38. set regData=%%b
  39. )
  40. )
  41. echo [DEBUG] The value of %regValue% is: %regData%
  42. @if "%regData%" == "" (
  43. @echo cannot found ProductName
  44. ) else (
  45. @echo %regData% | findstr "8.1" >nul && (
  46. @set SystermVer=8
  47. )
  48. @echo %regData% | findstr "10" >nul && (
  49. @set SystermVer=10
  50. )
  51. )
  52. echo [DEBUG] Windows Version: %SystermVer%
  53. @Set RunVersionPath=
  54. @rem 0:explorer.exe
  55. @rem 1:vbs
  56. @rem 2:vtm.exe
  57. @rem 3:startmenu lnk from RVCTermimalApplicationSetup
  58. @rem 4:startmenu lnk from install scripts
  59. @rem 404:unknown
  60. @Set CurAutoStartType=404
  61. @set NewAutoStartLnkName=spexplorerauto.lnk
  62. @rem 获取当前的rvc目录
  63. @Set RVCPath=
  64. @Set RVCResourcePath=
  65. @for %%a in ("%~dp0.") do for %%b in ("%%~dpa.") do set RVCPath=%%~dpb
  66. @rem 获取Resources的目录
  67. @set testRVCPath=%RVCPath%
  68. @echo testRVCPath=%testRVCPath%
  69. @for %%i in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do call set testRVCPath=%%testRVCPath:%%i=%%i%%
  70. @echo %testRVCPath% | findstr "rvc\\" >nul && (
  71. @Set RVCResourcePath=%RVCPath%Resources
  72. )
  73. @echo RVCResourcePath=%RVCResourcePath%
  74. @if "%RVCResourcePath%" == "" (
  75. @set errmsg=cannot found rvc path[%RVCPath%]
  76. @set ret=-10
  77. @goto UserError
  78. )
  79. @if not exist "%RVCResourcePath%" md "%RVCResourcePath%"
  80. @set DestAppIconPath=%RVCResourcePath%\VTM.ico
  81. @set SrcAppIconPath=%ROOT%\VTM.ico
  82. @if not exist "%DestAppIconPath%" (
  83. @if not exist "%SrcAppIconPath%" (
  84. @set errmsg=%SrcAppIconPath% does not exist
  85. @set ret=-4
  86. @goto UserError
  87. )
  88. @copy "%SrcAppIconPath%" %DestAppIconPath%
  89. )
  90. @rem 设置桌面壁纸
  91. :SetWallpaper
  92. @echo result=-1^&msg=set wallpaper >%resultFile%
  93. @set RVCWallpaperName=WallPaper1920.png
  94. @set regKey=HKEY_CURRENT_USER\Control Panel\Desktop
  95. @set regValue=Wallpaper
  96. @set regData=
  97. for /f "tokens=2*" %%a in ('reg query "%regKey%" /v "%regValue%" ^| findstr /i "%regValue%"') do (
  98. set regData=%%b
  99. )
  100. @echo [DEBUG] The value of %regValue% is: %regData%
  101. @if "%regData%" == "" (
  102. echo [DEBUG] to get Wallpaper twice
  103. for /f "tokens=2*" %%a in ('reg query "\"%regKey%\"" /v "%regValue%" ^| findstr /i "%regValue%"') do (
  104. set regData=%%b
  105. )
  106. )
  107. echo [DEBUG] The value of %regValue% is: %regData%
  108. @if "%regData%" == "" (
  109. @set errmsg=cannot found Wallpaper value
  110. @set ret=-5
  111. @goto UserError
  112. )
  113. @set WallpaperRegVal=%regData%
  114. @echo %regData% | findstr "%RVCWallpaperName%" >nul && (
  115. @if exist %WallpaperRegVal% (
  116. @echo [DEBUG] Wallpaper has been set before
  117. @set errmsg=Wallpaper has been set before
  118. @goto ClearSysDesktopIcon
  119. )
  120. )
  121. @set WallpaperPath=%ROOT%\%RVCWallpaperName%
  122. @set backupWallPaperPath=%ROOT%\\%RVCWallpaperName%
  123. @if not exist "%WallpaperPath%" (
  124. @Set errmsg=%WallpaperPath% does not exist
  125. @set ret=-6
  126. @goto UserError
  127. )
  128. @if not exist C:\Windows\Web\Wallpaper\%RVCWallpaperName% (
  129. @if exist "C:\Windows\Web\Wallpaper" (
  130. @copy "%WallpaperPath%" C:\Windows\Web\Wallpaper
  131. @set WallpaperPath=C:\Windows\Web\Wallpaper\%RVCWallpaperName%
  132. @set backupWallPaperPath=C:\\Windows\\Web\\Wallpaper\\%RVCWallpaperName%
  133. ) else (
  134. @copy "%WallpaperPath%" %RVCResourcePath%
  135. @set WallpaperPath=%RVCResourcePath%\%RVCWallpaperName%
  136. @set backupWallPaperPath=%RVCResourcePath%\\%RVCWallpaperName%
  137. )
  138. ) else (
  139. @set WallpaperPath=C:\Windows\Web\Wallpaper\%RVCWallpaperName%
  140. @set backupWallPaperPath=C:\\Windows\\Web\\Wallpaper\\%RVCWallpaperName%
  141. )
  142. @echo [DEBUG] WallpaperPath=%WallpaperPath%
  143. reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v Wallpaper /t REG_SZ /d "%WallpaperPath%" /f
  144. reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v WallpaperStyle /t REG_DWORD /d 2 /f
  145. @if %errorlevel% neq 0 (
  146. echo add for Desktop first failed
  147. reg add "\"HKEY_CURRENT_USER\Control Panel\Desktop\"" /v Wallpaper /t REG_SZ /d "%WallpaperPath%" /f
  148. reg add "\"HKEY_CURRENT_USER\Control Panel\Desktop\"" /v WallpaperStyle /t REG_DWORD /d 2 /f
  149. @if !errorlevel! neq 0 (
  150. @set errmsg=Set Wallpaper failed
  151. @set ret=-11
  152. @goto UserError
  153. )
  154. )
  155. @rem 清理桌面系统图标
  156. :ClearSysDesktopIcon
  157. @set errmsg=to clear desktop system icon
  158. reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel" /v {20D04FE0-3AEA-1069-A2D8-08002B30309D} /t REG_DWORD /d 1 /f
  159. reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu" /v {20D04FE0-3AEA-1069-A2D8-08002B30309D} /t REG_DWORD /d 1 /f
  160. reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel" /v {645FF040-5081-101B-9F08-00AA002F954E} /t REG_DWORD /d 1 /f
  161. reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu" /v {645FF040-5081-101B-9F08-00AA002F954E} /t REG_DWORD /d 1 /f
  162. reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel" /v {F02C1A0D-BE21-4350-88B0-7367FC96EF3C} /t REG_DWORD /d 1 /f
  163. reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu" /v {F02C1A0D-BE21-4350-88B0-7367FC96EF3C} /t REG_DWORD /d 1 /f
  164. reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel" /v {5399E694-6CE5-4D6C-8FCE-1D8870FDCBA0} /t REG_DWORD /d 1 /f
  165. reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu" /v {5399E694-6CE5-4D6C-8FCE-1D8870FDCBA0} /t REG_DWORD /d 1 /f
  166. reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel" /v {59031a47-3f72-44a7-89c5-5595fe6b30ee} /t REG_DWORD /d 1 /f
  167. reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu" /v {59031a47-3f72-44a7-89c5-5595fe6b30ee} /t REG_DWORD /d 1 /f
  168. @if %SystermVer% equ 8 (
  169. @echo 针对WIN8取消开机显示开始页面而直接进入桌面的选项
  170. reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StartPage" /v OpenAtLogon /t REG_DWORD /d 0 /f
  171. )
  172. @rem 设置桌面图标
  173. : setDesktopIcon
  174. @echo result=-1^&msg=set app desktop icon >%resultFile%
  175. @set errmsg=set app desktop icon
  176. @if not "%RunVersionPath%" == "" (
  177. @if exist "%RunVersionPath%" (
  178. if exist "%RunVersionPath%vtm.exe" (
  179. @echo version path got previously
  180. @goto SkipGetRunVersionPath
  181. )
  182. )
  183. )
  184. @echo [DEBUG] to get version path from syspath
  185. @set SYSPATH=%Path%
  186. @set VendorPath=%RVC_VENDOR_HOME%
  187. @rem 拆分环境变量获取Run/version目录
  188. @set manuSysPath=%SYSPATH%
  189. @for %%i in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do call set manuSysPath=%%manuSysPath:%%i=%%i%%
  190. @echo path=%manuSysPath%
  191. @rem Mark1
  192. @set prefixPath=
  193. @set tofind=run\version
  194. @set aimStr=version
  195. @set aimLen=7
  196. @set foundstr=
  197. :loop
  198. ::从环境变量中得到版本的路径
  199. @for /f "tokens=1* delims=;" %%a in ("%manuSysPath%") do (
  200. @set str=%%a
  201. @echo !str! | findstr "%tofind%" >nul && (
  202. @set foundstr=!str!
  203. @goto foundit
  204. )
  205. @set manuSysPath=%%b
  206. )
  207. if defined manuSysPath goto :loop
  208. if "%foundstr%" == "" (
  209. @set errmsg=cannot fetch Run path from Env::path
  210. @set ret=-7
  211. @goto UserError
  212. )
  213. :foundit
  214. @rem 从全路径里头获取version结尾
  215. @echo foundstr=%foundstr%
  216. @set fulStr=%foundstr%
  217. :next
  218. if not "%fulStr%" == "" (
  219. @set /a num+=1
  220. if "!fulStr:~0,%aimLen%!" == "%aimStr%" goto subfoundit
  221. @set fulStr=%fulStr:~1%
  222. goto next
  223. )
  224. @set /a num=0
  225. :subfoundit
  226. @echo num=%num%
  227. @set /a realnum=%aimLen%+%num%
  228. @if %num% neq 0 (
  229. @set prefixPath=!foundstr:~0,%realnum%!
  230. )
  231. @echo prefixPath=%prefixPath%
  232. @if "prefixPath" == "" (
  233. @set errmsg=cannot get run version path
  234. @set ret=-8
  235. @goto UserError
  236. )
  237. @set RunVersionPath=%prefixPath%
  238. @echo RunVersionPath=%RunVersionPath%
  239. :SkipGetRunVersionPath
  240. @rem 得到vtm.exe全路径
  241. @set vtmfulPath=%RunVersionPath%vtm.exe
  242. @echo vtm exe full path is %vtmfulPath%
  243. @if not exist "%vtmfulPath%" (
  244. @echo [ERROR] %vtmfulPath% does not exist
  245. @set errmsg=%vtmfulPath% does not exist
  246. @set ret=-9
  247. @goto UserError
  248. )
  249. @set desk_path=%USERPROFILE%\Desktop
  250. @set desk_path_pub=C:\Users\Public\Desktop
  251. @for %%a in (%desk_path%\*) do echo [DEBUG] desktop file: "%%a"
  252. @for %%a in (%desk_path_pub%\*) do echo [DEBUG] public desktop file: "%%a"
  253. @echo to clear desktop file
  254. @for /d %%a in (%desk_path%\*) do rd /S /Q "%%a"
  255. @for /d %%a in (%desk_path_pub%\*) do rd /S /Q "%%a"
  256. @for %%a in (%desk_path%\*) do del "%%a"
  257. @for %%a in (%desk_path_pub%\*) do del "%%a"
  258. mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b1=a.CreateShortcut(a.SpecialFolders(""Desktop"") & ""\可视柜台.lnk""):b1.TargetPath=""%vtmfulPath%"":b1.WorkingDirectory=""%RunVersionPath%"":b1.Description=""招行可视柜台终端应用"":b1.Save:close")
  259. @if exist "%desk_path%\可视柜台.lnk" (
  260. @echo [DEBUG] deskop icon is exist
  261. )
  262. @echo [DEBUG] set deskop app icon done
  263. @set errmsg=all process has been executed succ
  264. :Done
  265. @set ret=0
  266. @echo all process has been executed done
  267. @goto End
  268. :Error
  269. @set ret=-1
  270. :UserError
  271. @echo [Error] %errmsg%
  272. :End
  273. @echo result=%ret%^&msg=%errmsg% >%resultFile%
  274. @echo result=%ret%^&msg=%errmsg%
  275. @echo %date:~0,4%-%date:~5,2%-%date:~8,2% %time:~0,2%:%time:~3,2%:%time:~6,2%
  276. @exit 0