快速安装ArcGIS Pro 3.1.6的Batch脚本

  1 @echo off
  2 
  3 REM +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  4 REM ESRI ArcGIS Pro 3.1.6的激活脚本;                                                     +
  5 REM 由于记录了对应版本文件的SHA256哈希值,所以仅对3.1.6版本有效;                               +
  6 REM 所谓“部署”,仅仅是替换AfCore.dll,AfCore_Licensing.dll文件,添加注册表信息;               +
  7 REM 采用Mining_Ghost方案,文件来自公开的网络;                                              +
  8 REM 有条件的情况下,请支持正版。                                                            +
  9 REM 运行逻辑:                                                                           +
 10 REM   1.先检测是否有ESRI账号的登录信息,如果有,则关闭自动登录,以免出现不可预见的账号问题;         +
 11 REM   2.检测ArcGIS Pro是否安装;                                                          +
 12 REM   3.检测ArcGIS Pro 3.1.6更新包是否安装,如果没有,则检测ArcGIS Pro的版本,并对安装进行提示;  +
 13 REM   4.检测ArcGIS Pro是否在运行,如果在运行,则提示关闭;                                    +
 14 REM   5.对比ArcGIS Pro安装目录中的AfCore.dll的SHA256哈希值,判断当前程序的状态;               +
 15 REM   6.根据当前程序的安装状态,给出操作菜单,根据用户的选择,进行相应的操作。                     +
 16 REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 17 
 18 title ArcGIS Pro Tool for 3.1.6
 19 
 20 setlocal EnableDelayedExpansion
 21 
 22 echo.
 23 
 24 REM 获取管理员权限
 25 :getAdmin
 26 >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
 27 if '%errorlevel%' neq '0' (
 28 goto UACPrompt
 29 ) else ( goto gotAdmin )
 30 :UACPrompt
 31 echo set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
 32 echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
 33 "%temp%\getadmin.vbs"
 34 exit /b
 35 :gotAdmin
 36 if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
 37 
 38 REM 如果当前有ESRI账号登录,则关闭自动登录
 39 reg add "HKCU\SOFTWARE\ESRI\ArcGIS Online For Pro\SignIn\www.arcgis.com" /v "AutoSign" /t REG_DWORD /d 0 /f >nul 2>nul
 40 
 41 REM 检查是否安装ArcGIS Pro
 42 :ChkExist
 43 reg query "HKLM\SOFTWARE\ESRI\ArcGISPro\Settings" /v ArcGISPro_Install_ID >nul 2>nul && goto ChkPatch || echo 你未安装ArcGIS Pro,3秒后自动退出 && goto bye
 44 
 45 REM 检查是否安装ArcGIS Pro 3.1.6更新包(先检查更新包信息)
 46 :ChkPatch
 47 reg query "HKLM\SOFTWARE\ESRI\ArcGISPro\Updates\3.1_0_6" >nul 2>nul && goto GetInsDir || goto ChkRealVersion
 48 
 49 REM 检查安装的ArcGIS Pro版本是否是3.1
 50 :ChkRealVersion
 51 for /f "tokens=3 delims= " %%q in ('reg query "HKLM\SOFTWARE\ESRI\ArcGISPro" /v RealVersion') do (
 52   if "%%q"=="3.1" ( echo 您当前已安装ArcGIS Pro 3.1,但未安装3.1.6更新包,请安装后重试... && goto Bye ) else ( echo 你当前的安装版本为ArcGIS Pro %%q,请安装3.1.6版本... && goto Bye ) 
 53 )
 54 
 55 REM 获取ArcGIS Pro 安装目录
 56 :GetInsDir
 57 for /f "tokens=1,2 delims=:" %%a in ( 'reg query "HKLM\SOFTWARE\ESRI\ArcGISPro" /v InstallDir' ) do ( 
 58     set "value1=%%a"
 59     set "value2=%%b" 
 60  )
 61 set "gispath=%value1:~-1%:%value2%"
 62 goto ChkRunning
 63 
 64 REM 检查ArcGIS Pro是否在运行
 65 :ChkRunning
 66 REM 检查ArcGIS Pro是否在运行
 67 :ChkRunning
 68 tasklist /fi "IMAGENAME eq ArcGISPro.exe" | find /i "ArcGISPro.exe" >nul  
 69 if %errorlevel%==0 (  
 70     echo 检测到ArcGIS Pro正在运行,请先关闭程序...
 71     goto Bye
 72 ) else (
 73     goto deploy
 74 )
 75 
 76 REM 部署环节
 77 :deploy
 78 REM 设置ArcGIS Pro安装目录
 79 set "agpbinPath=!gispath!bin"
 80 set "currentPath=!agpbinPath!\AfCore.dll"
 81 set "currentLicPath=!agpbinPath!\AfCore_Licensing.dll"
 82 set "currentSHA256="
 83 set "currentLicSHA256="
 84 
 85 echo 当前ArcGIS Pro安装目录:!gispath!
 86 echo.
 87 
 88 
 89 REM 获取当前系统AfCore.dll的SHA256值,并直接解析输出
 90 for /f "tokens=*" %%i in ('certutil -hashfile "!currentPath!" SHA256 ^| findstr /V "hash"') do (
 91     set "currentSHA256=%%i"
 92 )
 93 
 94 REM 获取当前系统AfCore_Licensing.dll的SHA256值,并直接解析输出
 95 if exist "!currentLicPath!" (
 96     for /f "tokens=*" %%i in ('certutil -hashfile "!currentLicPath!" SHA256 ^| findstr /V "hash"') do (
 97     set "currentLicSHA256=%%i"
 98     )
 99 )
100 
101 
102 REM 将原版AfCore.dll的SHA-256值赋予esriSHA256
103 REM 原版SHA256查询链接 https://support.esri.com/en-us/knowledge-base/arcgis-pro-crashes-and-the-message-arcgis-pro-cannot-co-000028572
104 set "esriSHA256=be6b911286b8b9598358b1d8f43d63d209b1ba5bdda387c31a5b0e1b701d25f0"
105 
106 REM 将修改版的AfCore.dll的SHA-256值赋予mining_ghostSHA256
107 set "mining_ghostSHA256=4c41ac2d9f4ce002056c2aa3cdb93542e4883d67c59294e95fd7d4ca8e741095"
108 REM 将修改版的AfCore_Licensing.dll的SHA-256值赋予mining_ghostLicSHA256
109 set "mining_ghostLicSHA256=78c3c26abed9df35ce6b4a117692c981aa13073c244314d819d3a411c21122ac"
110 
111 REM 另外两种方案的Afcore.dll文件SHA256值
112 set "otherType1=7850fbe94fe45a0848895ec11376c0823055c1e079bead77de96d1e775d6bcd3"
113 set "otherType2=314534893c8b141ef43f038a9237f3a6addbf7de8a47d6b82e2f2ba564034494"
114 
115 REM 创建变量来记录匹配状态
116 set "matchType="
117 
118 REM 比较SHA256值
119 if "!currentSHA256!" == "!mining_ghostSHA256!" (
120     set "matchType=1"
121     echo ===您当前已使用 Mining_Ghost 方案===
122     echo.
123     goto menu
124 ) else if "!currentSHA256!" == "!esriSHA256!" (
125     set "matchType=0"
126     echo ===您当前的安装为ESRI官方原版===
127     echo.
128     goto menu
129 ) else if "!currentSHA256!" == "!otherType1!" (
130     set "matchType=2"
131     echo ===您当前已使用已知的另外一种方案部署===
132     echo.
133     goto menu
134 ) else if "!currentSHA256!" == "!otherType2!" (
135     set "matchType=2"
136     echo ===您当前已使用已知的另外一种方案部署===
137     echo.
138     goto menu
139 ) else (
140     echo ===您当前的安装与已知的任何版本都不匹配===
141     echo.
142     goto menu
143 )
144 
145 REM 显示菜单
146 :menu
147 echo.
148 echo 请选择一个操作选项:
149 if "!matchType!" == "1" (
150     echo [R] 恢复原版
151     echo [E] 退出程序
152     echo.
153     set /p "userChoice=请输入您的选择: "
154     if /i "!userChoice!" == "R" (
155         goto apply_Original
156     ) else if /i "!userChoice!" == "E" (
157         goto Bye
158     ) else (
159         goto menu_error
160     )
161 )else if "!matchType!" == "0" (
162     echo [1] 应用 Mining_Ghost 方案
163     echo [E] 退出程序
164     echo.
165     set /p "userChoice=请输入您的选择: "
166     if "!userChoice!" == "1" (
167         goto apply_Mining_Ghost
168     ) else if /i "!userChoice!" == "E" (
169         goto Bye
170     ) else (
171         goto menu_error
172     )
173 ) else (
174     echo [1] 应用 Mining_Ghost 方案
175     echo [R] 恢复原版
176     echo [E] 退出程序
177     echo.
178     set /p "userChoice=请输入您的选择: "
179     if "!userChoice!" == "1" (
180         goto apply_Mining_Ghost
181     ) else if /i "!userChoice!" == "R" (
182         goto apply_Original
183     ) else if /i "!userChoice!" == "E" (
184         goto Bye
185     ) else (
186         goto menu_error
187     )
188 )
189 
190 :apply_Mining_Ghost
191 echo 正在应用 Mining_Ghost 方案 ...
192 reg query "HKCU\Software\ESRI\ArcGISPro\Licensing" >nul 2>nul && reg delete "HKCU\Software\ESRI\ArcGISPro\Licensing" /f >nul 2>&1
193 if !matchType! ==0 (
194     ren "!agpbinPath!\AfCore.dll" "AfCore.dll.bak" >nul 2>&1
195     if not "!currentLicSHA256!" == "!mining_ghostLicSHA256!" (
196         ren "!currentLicPath!" "AfCore_Licensing.dll.bak" >nul 2>&1
197         )
198 )
199 copy /Y "%~dp0Regfiles\patch_Mining_Ghost\AfCore.dll" "!agpbinPath!"  >nul 2>&1
200 copy /Y "%~dp0Regfiles\patch_Mining_Ghost\AfCore_Licensing.dll" "!agpbinPath!"  >nul 2>&1
201 reg import "%~dp0Regfiles\patch_Mining_Ghost\agp.reg"  >nul 2>&1
202 echo ArcGIS Pro 3.1.6部署完毕,请尝试启动程序...
203 goto Bye
204 
205 :apply_Original
206 echo 正在 恢复原版 ...
207 reg query "HKCU\Software\ESRI\ArcGISPro\Licensing" >nul 2>nul && reg delete "HKCU\Software\ESRI\ArcGISPro\Licensing" /f >nul 2>&1
208 reg add "HKCU\SOFTWARE\ESRI\ArcGIS Online For Pro\SignIn\www.arcgis.com" /v "AutoSign" /t REG_DWORD /d 1 /f >nul 2>nul
209 if "!currentLicSHA256!" == "!mining_ghostLicSHA256!" (
210     del "!currentLicPath!" >nul 2>&1
211 )
212 del "%agpbinPath%\AfCore_Licensing.dll.bak" >nul 2>&1
213 del "%agpbinPath%\AfCore.dll.bak" >nul 2>&1
214 copy /Y "%~dp0Regfiles\esri_original\AfCore.dll" "!agpbinPath!"  >nul 2>&1
215 echo 请打开程序,登录ESRI账号使用...
216 goto Bye
217 
218 :menu_error
219 echo 选择无效,请重试。
220 ECHO !matchType!
221 goto menu
222 
223 :Bye
224 echo 现在退出...
225 choice /t 3 /d y /n >nul
226 exit
227 
228 endlocal

目录结构:

./
├── ArcGIS_Pro3.1.6_Tool.bat
└── Regfiles
    ├── esri_original
    │   └── AfCore.dll
    └── patch_Mining_Ghost
        ├── AfCore.dll
        ├── AfCore_Licensing.dll
        └── agp.reg
posted @ 2024-06-20 08:52  MeGusta  阅读(116)  评论(0编辑  收藏  举报