@ECHO OFF&(PUSHD "%~DP0")&(REG QUERY "HKU\S-1-5-19">NUL 2>&1)||(
powershell -Command "Start-Process '%~sdpnx0' -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
rd/s/q "%CommonProgramFiles%\Macrovision Shared"2>NUL
rd/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

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 NOT EXIST "%ProgramW6432%" (
::标记软件所在路径
reg add "HKLM\SOFTWARE\NetSarang\Xftp\7" /f /v "Path" /d "%~dp0\" >NUL 2>NUL
reg add "HKLM\SOFTWARE\NetSarang\Xshell\7" /f /v "Path" /d "%~dp0\" >NUL 2>NUL
::关于显示版本号（如无该键值关于对话框则不显示版本号）
reg add "HKLM\SOFTWARE\NetSarang\Xftp\7" /f /v "Version" /d "7.0.0106" >NUL 2>NUL
reg add "HKLM\SOFTWARE\NetSarang\Xshell\7" /f /v "Version" /d "7.0.0108" >NUL 2>NUL
::必要产品检测信息（如果不存这二进制数据在则启动失败）
reg add "HKLM\SOFTWARE\NetSarang\Xftp\7" /f /v "MagicCode" /t REG_BINARY /d "7f740cdc7d5fa37bea575ad92d78de73e60704000c00" >NUL 2>NUL
reg add "HKLM\SOFTWARE\NetSarang\Xshell\7" /f /v "MagicCode" /t REG_BINARY /d "7f740cdc7d5fa37bea575ad92d78de73e60704000c00" >NUL 2>NUL
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDlls" /f /v "%~dp0XshellCore.tlb">NUL 2>NUL
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDlls" /f /v "%~dp0XftpCore.tlb">NUL 2>NUL
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDlls" /f /v "%~dp0NsCopyHook3.dll" /t REG_DWORD /d "1" >NUL 2>NUL
) ELSE (
reg add "HKLM\SOFTWARE\NetSarang\Xftp\7" /f /v "Path" /d "%~dp0\" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\NetSarang\Xftp\7" /f /v "Version" /d "7.0.0106" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDlls" /f /v "%~dp0XftpCore.tlb" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDlls" /f /v "%~dp0NsCopyHook3.dll" /t REG_DWORD /d "1" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\NetSarang\Xftp\7" /f /v "MagicCode" /t REG_BINARY /d "7f740cdc7d5fa37bea575ad92d78de73e60704000c00" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\NetSarang\Xshell\7" /f /v "Path" /d "%~dp0\" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\NetSarang\Xshell\7" /f /v "Version" /d "7.0.0108" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDlls" /f /v "%~dp0XshellCore.tlb" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\NetSarang\Xshell\7" /f /v "MagicCode" /t REG_BINARY /d "7f740cdc7d5fa37bea575ad92d78de73e60704000c00" /reg:32 >NUL 2>NUL

)

::创建桌面快捷方式
mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(a.SpecialFolders(""Desktop"") & ""\Xftp.lnk""):b.TargetPath=""%~sdp0Xftp.exe"":b.WorkingDirectory=""%~sdp0"":b.Save:close")
mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(a.SpecialFolders(""Desktop"") & ""\Xshell.lnk""):b.TargetPath=""%~sdp0Xshell.exe"":b.WorkingDirectory=""%~sdp0\"":b.Save:close")

ECHO.&ECHO 完成 &TIMEOUT /t 2 >NUL&EXIT