original.bat 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. @setlocal enabledelayedexpansion
  2. @echo off
  3. @rem 要求以管理员方式启动
  4. bcdedit >nul
  5. if '%errorlevel%' NEQ '0' (goto UACPrompt) else (goto UACAdmin)
  6. :UACPrompt
  7. %1 start "" mshta vbscript:createobject("shell.application").shellexecute("""%~0""","::",,"runas",1)(window.close)&exit
  8. exit /B
  9. :UACAdmin
  10. color 0F
  11. @cls
  12. title 【可视柜台应用程序安装脚本】
  13. for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
  14. set "DEL=%%a"
  15. )
  16. cd /d "%~dp0"
  17. @set /a argumentNum=0
  18. @set ret=0
  19. @rem 1 关机 2 重启
  20. @set poweroffPC=0
  21. @set /a installType=0
  22. @set installPure=1
  23. @for %%a in (%*) do set /a argumentNum+=1
  24. @if %argumentNum% gtr 0 (
  25. @echo argument count: %argumentNum%
  26. @if %argumentNum% == 1 (
  27. @if "%1" == "uninstall" (
  28. @set installType=4
  29. ) else if "%1" == "pure" (
  30. @set installType=1
  31. )
  32. )
  33. ) else (
  34. @echo no any arguments
  35. )
  36. @echo [RVCTermianal] ========== Install Start ==========
  37. @echo 安装脚本模式: %installType%
  38. @set sysProductKey=
  39. for /f "skip=1 delims==" %%i in ('wmic path softwarelicensingservice get OA3xOriginalProductKey') do (
  40. @set sysProductKey=%%i
  41. @goto DoneGetProductKey
  42. )
  43. :DoneGetProductKey
  44. @echo sysProductKey=%sysProductKey%
  45. if "%sysProductKey%" == "" (
  46. @echo [DEBUG] 操作系统未激活!
  47. ) else (
  48. @echo [DEBUG] 操作系统已激活。
  49. )
  50. @set ROOT=%cd%
  51. @set rvc_src_path_rvc_dir=%ROOT%\rvc
  52. @set rvc_src_path_Run_dir=%ROOT%\Run
  53. @set rvc_src_path_rvc_res_dir=%rvc_src_path_rvc_dir%\Resources
  54. @set rvc_install_path_root=%HOMEDRIVE%:
  55. @set sysdisk=1
  56. @set lnkPath=spexplorerauto.lnk
  57. @set AutoStartDir=C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
  58. @set AutoStartDir2=C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
  59. @set VS2019MarkFile=C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\devenv.exe
  60. @set RVCTerminalDirName=
  61. @set RVCTerminalDirFullPath=
  62. @set RVCCurInstallVersion=
  63. tasklist /nh | find /i "spshell.exe"
  64. @if errorlevel 1 (
  65. @echo [INFO] 可视柜台进程不存在,跳过进程清理
  66. ) else (
  67. @echo [INFO] 检测到可视柜台进程存在,开始清理可视柜台相关进程……
  68. TASKKILL /F /IM spshell.exe
  69. TASKKILL /F /IM guardian.exe
  70. TASKKILL /F /IM cefclient.exe
  71. @for /f "tokens=1,2 delims= " %%a in ('tasklist /m ^| findstr "sphost.exe"') do (
  72. @echo name=%%a, PID = %%b, and will kill it.
  73. TASKKILL /F /PID %%a
  74. )
  75. )
  76. @rem 如果是非生产环境并且且是开发者的电脑在安装版本,那么部分公共的设置不生效,例如壁纸,开机自启动
  77. @if %installType% equ 0 (
  78. @if exist "%VS2019MarkFile%" (
  79. @call :ColorText E0 "[WARN] 检测到当前安装的系统环境为开发人员环境,将跳过部分设置,避免影响开发日常工作"
  80. @set installPure=0
  81. )
  82. )
  83. @echo [DEBUG] installPure=%installPure%
  84. @if exist "D:\\" (
  85. @if exist "D:\\Run\\version\\vtm.exe" (
  86. @set rvc_install_path_root=D:
  87. @set sysdisk=0
  88. ) else (
  89. @set rvc_install_path_root=D:
  90. @set sysdisk=0
  91. )
  92. )
  93. @echo [DEBUG] rvc_install_path_root=%rvc_install_path_root%
  94. @echo [DEBUG] rvc_src_path_Run_dir=%rvc_src_path_Run_dir%
  95. @set rvc_install_path_rvc_dir=%rvc_install_path_root%\rvc
  96. @set rvc_install_path_rvc_res_dir=%rvc_install_path_root%\rvc\Resources
  97. @set rvc_install_path_Run_dir=%rvc_install_path_root%\Run
  98. @set rvc_install_path_hardware_dir=%rvc_install_path_Run_dir%\hardwarecfg
  99. @set rvc_install_path_versions_dir=%rvc_install_path_Run_dir%\version
  100. @echo [DEBUG] rvc_install_path_rvc_dir=%rvc_install_path_rvc_dir%
  101. @echo [DEBUG] rvc_install_path_rvc_res_dir=%rvc_install_path_rvc_res_dir%
  102. @echo [DEBUG] rvc_install_path_Run_dir=%rvc_install_path_Run_dir%
  103. @echo [DEBUG] rvc_install_path_hardware_dir=%rvc_install_path_hardware_dir%
  104. @echo [DEBUG] rvc_install_path_versions_dir=%rvc_install_path_versions_dir%
  105. @echo 【0/1】拷贝RVC目录...
  106. @if not exist "%rvc_src_path_rvc_res_dir%" (
  107. @call :ColorText 4F "[ERROR] Resources文件夹不存在,请检查安装包的合法性和完整性!!"
  108. @goto InstallError
  109. )
  110. @if not exist "%rvc_install_path_rvc_dir%" md "%rvc_install_path_rvc_dir%"
  111. @if not exist "%rvc_install_path_rvc_res_dir%" md "%rvc_install_path_rvc_res_dir%"
  112. @xcopy "%rvc_src_path_rvc_res_dir%" %rvc_install_path_rvc_res_dir% /E/Y/Q
  113. @echo 【1/1】拷贝RVC目录OK!
  114. @if not exist "%rvc_src_path_Run_dir%" (
  115. @call :ColorText 4F "[ERROR] Run版本文件夹不存在,请检查安装包的合法性和完整性!!"
  116. @goto InstallError
  117. )
  118. @if not exist "%rvc_src_path_Run_dir%\version" (
  119. @call :ColorText 4F "[ERROR] version文件夹不存在,请检查安装包的合法性和完整性!!"
  120. @goto InstallError
  121. )
  122. @if not exist "%rvc_install_path_Run_dir%" md "%rvc_install_path_Run_dir%"
  123. @if not exist "%rvc_install_path_hardware_dir%" md "%rvc_install_path_hardware_dir%"
  124. @if not exist "%rvc_install_path_versions_dir%" md "%rvc_install_path_versions_dir%"
  125. @echo 【1/2】拷贝终端版本,文件数量较多,部分终端拷贝时间比较长,请稍加等候......
  126. @if exist "%rvc_src_path_Run_dir%\hardwarecfg" ( xcopy "%rvc_src_path_Run_dir%\hardwarecfg" "%rvc_install_path_hardware_dir%" /E/Y/Q )
  127. @xcopy "%rvc_src_path_Run_dir%\version" "%rvc_install_path_versions_dir%" /E/Y/Q
  128. @echo 【2/2】拷贝终端版本OK!
  129. @echo 【2/3】设置系统桌面壁纸
  130. @set FileCount=0
  131. @set desk_path=%USERPROFILE%\Desktop
  132. @set desk_path_pub=C:\Users\Public\Desktop
  133. @echo [DEBUG] desk_path=%desk_path%
  134. @if %installPure% equ 0 (
  135. @call :ColorText E0 "[WARN] 开发设备不清理桌面和设置壁纸,直接跳过"
  136. @goto doNotRunUpdatePerEtc
  137. )
  138. @echo [INFO] 清理桌面文件内容
  139. @for /d %%a in (%desk_path%\*) do (
  140. @echo [DEBUG] %%a
  141. @rd /S /Q "%%a"
  142. )
  143. @for %%a in (%desk_path%\*) do (
  144. @echo [DEBUG] %%a
  145. @del "%%a"
  146. )
  147. @for /d %%a in (%desk_path_pub%\*) do (
  148. @echo [DEBUG] %%a
  149. @rd /S /Q "%%a"
  150. )
  151. @for %%a in (%desk_path_pub%\*) do (
  152. @echo [DEBUG] %%a
  153. @del "%%a"
  154. )
  155. @echo [INFO] 清理桌面 此电脑 图标
  156. reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel" /v {20D04FE0-3AEA-1069-A2D8-08002B30309D} /t REG_DWORD /d 1 /f
  157. reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu" /v {20D04FE0-3AEA-1069-A2D8-08002B30309D} /t REG_DWORD /d 1 /f
  158. @echo [INFO] 清理桌面 回收站 图标
  159. reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel" /v {645FF040-5081-101B-9F08-00AA002F954E} /t REG_DWORD /d 1 /f
  160. reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu" /v {645FF040-5081-101B-9F08-00AA002F954E} /t REG_DWORD /d 1 /f
  161. @echo [INFO] 清理桌面 网络 图标
  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. @echo [INFO] 清理桌面 控制面板 图标
  165. reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel" /v {5399E694-6CE5-4D6C-8FCE-1D8870FDCBA0} /t REG_DWORD /d 1 /f
  166. reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu" /v {5399E694-6CE5-4D6C-8FCE-1D8870FDCBA0} /t REG_DWORD /d 1 /f
  167. @echo [INFO] 清理桌面 用户的文件 图标
  168. reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel" /v {59031a47-3f72-44a7-89c5-5595fe6b30ee} /t REG_DWORD /d 1 /f
  169. reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu" /v {59031a47-3f72-44a7-89c5-5595fe6b30ee} /t REG_DWORD /d 1 /f
  170. @echo [INFO] 清理桌面文件内容OK!
  171. @set backupWallPaperPath=%rvc_install_path_root%\\rvc\\Resources\\WallPaper1920.png
  172. @set WallpaperPath=%rvc_install_path_rvc_res_dir%\WallPaper1920.png
  173. @if not exist C:\Windows\Web\Wallpaper\WallPaper1920.png (
  174. @if exist "C:\Windows\Web\Wallpaper" (
  175. @if not exist "%WallpaperPath%" (
  176. @call :ColorText 4F "[ERROR] 壁纸资源文件不存在,请检查安装包的合法性和完整性!!"
  177. @goto InstallError
  178. )
  179. @copy "%WallpaperPath%" C:\Windows\Web\Wallpaper
  180. @set WallpaperPath=C:\Windows\Web\Wallpaper\WallPaper1920.png
  181. @set backupWallPaperPath=C:\\Windows\\Web\\Wallpaper\\WallPaper1920.png
  182. )
  183. ) else (
  184. @echo [DEBUG] 指定壁纸已存在系统目录
  185. @set WallpaperPath=C:\Windows\Web\Wallpaper\WallPaper1920.png
  186. @set backupWallPaperPath=C:\\Windows\\Web\\Wallpaper\\WallPaper1920.png
  187. )
  188. @echo [DEBUG] WallpaperPath=%WallpaperPath%
  189. @echo [INFO] 通过注册表设置桌面壁纸
  190. @set regWallpaperFile=%TEMP%\rvc_wallpaperset.reg
  191. reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v Wallpaper /t REG_SZ /d "%WallpaperPath%" /f
  192. reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v WallpaperStyle /t REG_DWORD /d 2 /f
  193. @if %errorlevel% neq 0 (
  194. @echo [DEBUG] backupWallPaperPath=%backupWallPaperPath%
  195. @echo Windows Registry Editor Version 5.00 > %regWallpaperFile%
  196. @echo. >> %regWallpaperFile%
  197. @echo [HKEY_CURRENT_USER\Control Panel\Desktop] >> %regWallpaperFile%
  198. @echo "Wallpaper"="%backupWallPaperPath%" >> %regWallpaperFile%
  199. @echo "WallpaperStyle"=dword:00000001 >> %regWallpaperFile%
  200. regedit /s %regWallpaperFile%
  201. @del %regWallpaperFile%
  202. )
  203. @call :ColorText E0 "[WARN] 通过注册表设置桌面壁纸OK!(部分机器需要重启后才生效,请注意观察)"
  204. @echo 【3/3】设置系统桌面壁纸OK!
  205. :doNotRunUpdatePerEtc
  206. @echo 【3/4】设置可视柜台应用程序开机自启动
  207. @echo [DEBUG] 读取注册表信息
  208. @set regFile=%TEMP%\rvc_spshellautostart.reg
  209. @set regTmpFile=%TEMP%\rvckey.txt
  210. @echo [DEBUG] %regFile%
  211. @echo [DEBUG] %regTmpFile%
  212. @set explorerKey=
  213. @set needSetAutoStartFlag=1
  214. @set explorerNormal=0
  215. regedit /e %regFile% "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
  216. @type %regFile% | find /I """Shell""=" > "%regTmpFile%"
  217. @for /f "usebackq delims== tokens=2" %%a in ("%regTmpFile%") do (
  218. @set explorerKey=%%~a
  219. )
  220. @del "%regFile%"
  221. @del "%regTmpFile%"
  222. @echo [DEBUG] original explorer key:%explorerKey%
  223. @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 explorerKey=%%explorerKey:%%i=%%i%%
  224. @echo [DEBUG] explorer key:%explorerKey%
  225. @if "%explorerKey%" == "explorer.exe" (
  226. @echo [DEBUG] 检测到未设置为开机自启动模式
  227. @set explorerNormal=1
  228. ) else if "%explorerKey%" == "d:\\run\\version\\vtm.exe" (
  229. @call :ColorText 2F "检测到已设置为VTM.exe开机自启动模式"
  230. @set needSetAutoStartFlag=0
  231. ) else if "%explorerKey%" == "wscript d:\\run\\version\\spexplorerfast.vbs" (
  232. @echo [DEBUG] 检测到已设置为VBS脚本开机自启动模式
  233. )
  234. @if %explorerNormal% neq 1 (
  235. @echo [DEBUG] 取消可视柜台应用程序开机自启动(同时恢复桌面)
  236. @echo [DEBUG] 临时存储取消开机自启动的注册表脚本
  237. @echo Windows Registry Editor Version 5.00 > %regFile%
  238. @echo. >> %regFile%
  239. @echo [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon] >> %regFile%
  240. @echo "Shell1"="d:\\run\\version\\vtm.exe" >> %regFile%
  241. @echo "Shell"="explorer.exe" >> %regFile%
  242. @echo [DEBUG] 更新注册表!
  243. regedit /s %regFile%
  244. @del %regFile%
  245. )
  246. @echo [DEBUG] 移除旧有的可视柜台自启动文件(如有)
  247. @echo [DEBUG] AutoStartDir=%AutoStartDir%
  248. @echo [DEBUG] AutoStartDir2=%AutoStartDir2%
  249. @if exist "%AutoStartDir%\%lnkPath%" (
  250. @echo [DEBUG] 移除自启动文件 %AutoStartDir%\%lnkPath%
  251. @del "%AutoStartDir%\%lnkPath%"
  252. )
  253. @if exist "%AutoStartDir2%\%lnkPath%" (
  254. @echo [DEBUG] 移除自启动文件 %AutoStartDir2%\%lnkPath%
  255. @del "%AutoStartDir2%\%lnkPath%"
  256. )
  257. @rem 移除旧有的可视柜台自启动快捷键(通过安装程序自动生成的)
  258. @for %%i in ("%AutoStartDir2%\招商银行可视柜台*.lnk") do (
  259. @echo [DEBUG] 移除自启动文件 %%i
  260. @del "%%i"
  261. )
  262. @set targetPath=%rvc_install_path_versions_dir%\vtm.exe
  263. @if %installPure% equ 1 goto setAutoStartAndDesktopIcon
  264. @call :ColorText E0 "[WARN] 开发设备不设置开机自启动,仅设置桌面图标"
  265. mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b1=a.CreateShortcut(a.SpecialFolders(""Desktop"") & ""\可视柜台.lnk""):b1.TargetPath=""%targetPath%"":b1.WorkingDirectory=""%rvc_install_path_versions_dir%"":b1.Description=""招行可视柜台终端应用"":b1.Save:close")
  266. @goto DoneAutostartSet
  267. :setAutoStartAndDesktopIcon
  268. @echo [INFO] 设置应用自启动和桌面图标
  269. @rem ResourceWatcher:可视柜台.lnk
  270. @rem RVCTerminalApplication:招商银行可视柜台.lnk
  271. mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(a.SpecialFolders(""startup"") & ""\%lnkPath%""):b.TargetPath=""%targetPath%"":b.WorkingDirectory=""%rvc_install_path_versions_dir%"":b.Description=""招行可视柜台终端应用"":b.Save:Set b1=a.CreateShortcut(a.SpecialFolders(""Desktop"") & ""\可视柜台.lnk""):b1.TargetPath=""%targetPath%"":b1.WorkingDirectory=""%rvc_install_path_versions_dir%"":b1.Description=""招行可视柜台终端应用"":b1.Save:close")
  272. :DoneAutostartSet
  273. @echo 【4/4】设置可视柜台应用程序开机自启动OK!
  274. @goto End
  275. :InstallError
  276. @set ret=1
  277. :End
  278. @if "%ret%" == "1" (
  279. @call :ColorText 4F "[ERROR] 安装失败,具体失败步骤见上方描述!!"
  280. @pause
  281. @goto Done
  282. )
  283. @for /d %%a in ("%rvc_src_path_Run_dir%\version\*") do (
  284. @set RVCTerminalDirFullPath=%%a
  285. @set RVCTerminalDirName=%%~nxa
  286. @goto GetRVCTerminalDirNameDone
  287. )
  288. :GetRVCTerminalDirNameDone
  289. @set RVCCurInstallVersion=%RVCTerminalDirName%
  290. @echo [DEBUG] RVCCurInstallVersion=%RVCCurInstallVersion%
  291. @call :ColorText 2F "[INFO] ===所有安装步骤执行成功,正常退出,请双击桌面图标启动可视柜台应用进入安装配置,可视柜台应用版本号:%RVCCurInstallVersion%==="
  292. @set /a timoutsecs=5
  293. @echo [INFO] %timoutsecs%s 后自动退出该执行脚本并最小化到桌面
  294. @for /l %%a in (1, 1, %timoutsecs%) do (
  295. timeout 1 > nul
  296. @set /a lastsecs=%timoutsecs%-%%a
  297. @echo [INFO] !lastsecs!s 后自动退出该执行脚本并最小化到桌面
  298. )
  299. @echo 最小化到桌面并退出脚本流程
  300. @rem MinimizeAll ToggleDesktop
  301. mshta VBScript:Execute("Set a=CreateObject(""Shell.Application""):a.MinimizeAll:close")
  302. @rem @start %rvc_install_path_versions_dir%
  303. :Done
  304. @exit %ret%
  305. :stringLenth
  306. @set thestring=%~1
  307. @if not defined theString (
  308. @set Return=0
  309. @set %2=0
  310. @goto :eof
  311. )
  312. @set Return=0
  313. :stringLenth_continue
  314. @set /a Return+=1
  315. @set thestring=%thestring:~0,-1%
  316. @if defined thestring goto stringLenth_continue
  317. @if not "%2"=="" set %2=%Return%
  318. @goto :eof
  319. :ColorText
  320. @rem color 2F 这里的2代表背景,F代表字色
  321. @rem 0=黑、1=蓝、2=绿、3=浅绿、4=红、5=紫、6=黄、7=白、8=灰、9=淡蓝、
  322. @rem A=淡绿、B=淡浅绿、C=淡红、D=淡紫、E=淡黄、F=亮白
  323. <nul set /p ".=%DEL%" > "%~2"
  324. @findstr /v /a:%1 /R "^$" "%~2" nul
  325. @del "%~2" > nul 2>&1
  326. @echo.
  327. @goto :eof