@ECHO OFF & PUSHD "%~DP0" && CD /D "%~DP0"
IF EXIST "%Public%" >NUL 2>&1 REG QUERY "HKU\S-1-5-19\Environment"
IF NOT %errorlevel% EQU 0 (
IF EXIST "%Public%" powershell.exe -windowstyle hidden -noprofile "Start-Process '%~dpnx0' -Verb RunAs"
EXIT
)

taskkill /f /im Xftp* >NUL 2>NUL
taskkill /f /im Xshell* >NUL 2>NUL
taskkill /f /im FNPLicensingService* >NUL 2>NUL

::清理许可证服务组件
net stop "FlexNet Licensing Service" >NUL 2>NUL
sc delete "FlexNet Licensing Service" >NUL 2>NUL
rmdir/s/q "%CommonProgramFiles%\Macrovision Shared"2>NUL
rmdir/s/q "%CommonProgramFiles(x86)%\Macrovision Shared"2>NUL
reg delete "HKCU\Software\Microsoft\NetLicense" /F>NUL 2>NUL
reg delete "HKCU\Software\Microsoft\NetLicense" /F>NUL 2>NUL
reg delete "HKLM\SYSTEM\CurrentControlSet\Services\FlexNet Licensing Service" /f >NUL 2>NUL

regsvr32 /s NsCopyHook3.dll

::关联会话文件格式
reg delete "HKCR\.xfp" /f >NUL 2>NUL
reg delete "HKCR\.xts" /f >NUL 2>NUL
reg delete "HKCR\.xsh" /f >NUL 2>NUL
reg delete "HKCR\Xftp.xfp" /f >NUL 2>NUL
reg delete "HKCR\Xshell.xsh" /f >NUL 2>NUL
reg delete "HKCR\Xtransport.xts" /f >NUL 2>NUL
reg add "HKLM\SOFTWARE\Classes\.xfp" /f /ve /d "Xftp.xfp" >NUL 2>NUL
reg add "HKLM\SOFTWARE\Classes\.xsh" /f /ve /d "Xshell.xsh" >NUL 2>NUL
reg add "HKLM\SOFTWARE\Classes\.xts" /f /ve /d "Xtransport.xts" >NUL 2>NUL
reg add "HKLM\SOFTWARE\Classes\Xftp.xfp\DefaultIcon" /f /ve /d "%~dp0Xftp.exe,0" >NUL 2>NUL
reg add "HKLM\SOFTWARE\Classes\Xftp.xfp\shell\open\command" /f /ve /d "\"%~dp0Xftp.exe\" \"%%1\"" >NUL 2>NUL
reg add "HKLM\SOFTWARE\Classes\Xshell.xsh" /f /ve /d "Xshell session" >NUL 2>NUL
reg add "HKLM\SOFTWARE\Classes\Xshell.xsh\DefaultIcon" /f /ve /d "%~dp0Xshell.exe,0" >NUL 2>NUL
reg add "HKLM\SOFTWARE\Classes\Xshell.xsh\shell\open\command" /f /ve /d "\"%~dp0Xshell.exe\" \"%%1\"" >NUL 2>NUL
reg add "HKLM\SOFTWARE\Classes\Xtransport.xts\shell\open" /f /ve /d "" >NUL 2>NUL
reg add "HKLM\SOFTWARE\Classes\Xtransport.xts\shell\open\command" /f /ve /d "\"%~dp0Xtransport.exe\" -f \"%%1\"" >NUL 2>NUL
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Xftp.exe" /f /ve /d "%~dp0Xftp.exe" >NUL 2>NUL
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Xshell.exe" /f /ve /d "%~dp0Xshell.exe" >NUL 2>NUL
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Xagent.exe" /f /ve /d "%~dp0Xagent.exe" >NUL 2>NUL
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Xactivator.exe" /f /ve /d "%~dp0Xactivator.exe" >NUL 2>NUL

::刷新关联会话文件图标
assoc .=.file >NUL 2>NUL

if "%PROCESSOR_ARCHITECTURE%"=="x86" reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDlls" /f /v "%~dp0XshellCore.tlb" /t REG_DWORD /d "1" >NUL 2>NUL
if "%PROCESSOR_ARCHITECTURE%"=="x86" reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDlls" /f /v "%~dp0NsCopyHook3.dll" /t REG_DWORD /d "1" >NUL 2>NUL
If "%PROCESSOR_ARCHITECTURE%"=="AMD64" reg add "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\SharedDlls" /f /v "%~dp0XshellCore.tlb" /t REG_DWORD /d "1" >NUL 2>NUL
If "%PROCESSOR_ARCHITECTURE%"=="AMD64" reg add "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\SharedDlls" /f /v "%~dp0NsCopyHook3.dll" /t REG_DWORD /d "1" >NUL 2>NUL

::定义软件所在位置
if "%PROCESSOR_ARCHITECTURE%"=="x86" reg add "HKLM\SOFTWARE\NetSarang\Xftp\6" /f /v "Path" /d "%~dp0\" >NUL 2>NUL
::关于显示版本号（如无该键值关于对话框则不显示版本号）
if "%PROCESSOR_ARCHITECTURE%"=="x86" reg add "HKLM\SOFTWARE\NetSarang\Xftp\6" /f /v "Version" /d "6.0.0191" >NUL 2>NUL
::产品必要检索信息（如果不存在该注册表数据则启动失败）
if "%PROCESSOR_ARCHITECTURE%"=="x86" reg add "HKLM\SOFTWARE\NetSarang\Xftp\6" /f /v "MagicCode" /t REG_BINARY /d "145C1B290A8739488F611AB94AC4E30FE40703001A00" >NUL 2>NUL
If "%PROCESSOR_ARCHITECTURE%"=="AMD64" reg add "HKLM\SOFTWARE\Wow6432Node\NetSarang\Xftp\6" /f /v "Path" /d "%~dp0\" >NUL 2>NUL
If "%PROCESSOR_ARCHITECTURE%"=="AMD64" reg add "HKLM\SOFTWARE\Wow6432Node\NetSarang\Xftp\6" /f /v "Version /d "6.0.0191" >NUL 2>NUL
if "%PROCESSOR_ARCHITECTURE%"=="AMD64" reg add "HKLM\SOFTWARE\Wow6432Node\NetSarang\Xftp\6" /f /v "MagicCode" /t REG_BINARY /d "145C1B290A8739488F611AB94AC4E30FE40703001A00" >NUL 2>NUL

if "%PROCESSOR_ARCHITECTURE%"=="x86" reg add "HKLM\SOFTWARE\NetSarang\Xshell\6" /f /v "Path /d "%~dp0\" >NUL 2>NUL
if "%PROCESSOR_ARCHITECTURE%"=="x86" reg add "HKLM\SOFTWARE\NetSarang\Xshell\6" /f /v "Version" /d "6.0.0197" >NUL 2>NUL
if "%PROCESSOR_ARCHITECTURE%"=="x86" reg add "HKLM\SOFTWARE\NetSarang\Xshell\6" /f /v "MagicCode" /t REG_BINARY /d  "145C1B290A8739488F611AB94AC4E30FE40703001A00" >NUL 2>NUL
If "%PROCESSOR_ARCHITECTURE%"=="AMD64" reg add "HKLM\SOFTWARE\Wow6432Node\NetSarang\Xshell\6" /f /v "Path" /d "%~dp0\" >NUL 2>NUL
If "%PROCESSOR_ARCHITECTURE%"=="AMD64" reg add "HKLM\SOFTWARE\Wow6432Node\NetSarang\Xshell\6" /f /v "Version" /d "6.0.0197" >NUL 2>NUL
if "%PROCESSOR_ARCHITECTURE%"=="AMD64" reg add "HKLM\SOFTWARE\Wow6432Node\NetSarang\Xshell\6" /f /v "MagicCode" /t REG_BINARY /d "145C1B290A8739488F611AB94AC4E30FE40703001A00" >NUL 2>NUL

mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(a.SpecialFolders(""Desktop"") & ""\Xshell.lnk""):b.TargetPath=""%~dp0Xshell.exe"":b.WorkingDirectory=""%~dp0\"":b.Save:close")
mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(a.SpecialFolders(""Desktop"") & ""\Xftp.lnk""):b.TargetPath=""%~dp0Xftp.exe"":b.WorkingDirectory=""%~dp0\"":b.Save:close")

ECHO.&ECHO 完成！ &PAUSE >NUL 2>NUL & EXIT