pushd "%~dp0" && Dism 1>nul 2>nul || mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 "%*"","","runas",1)(window.close) && Exit /B 1
echo off

taskkill /f /im Xshell* >NUL 2>NUL
taskkill /f /im Xftp* >NUL 2>NUL
taskkill /f /im Xmanager* >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 /reg:32 >NUL 2>NUL
reg delete "HKCU\Software\Microsoft\NetLicense" /F /reg:32 >NUL 2>NUL

::关联会话文件格式
reg delete "HKCR\.xfp" /f /reg:32 >NUL 2>NUL
reg delete "HKCR\.xsh" /f /reg:32 >NUL 2>NUL
reg delete "HKCR\.xts" /f /reg:32 >NUL 2>NUL
reg delete "HKCR\.xcas" /f /reg:32 >NUL 2>NUL
reg delete "HKCR\.xdts" /f /reg:32 >NUL 2>NUL
reg delete "HKCR\Xftp.xfp" /f /reg:32 >NUL 2>NUL
reg delete "HKCR\Xshell.xsh" /f /reg:32 >NUL 2>NUL
reg delete "HKCR\Xtransport.xts" /f /reg:32 >NUL 2>NUL
reg delete "HKCR\Xstart.session" /f /reg:32 >NUL 2>NUL
reg delete "HKCR\Xmanager.session" /f /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\Classes\.xfp" /f /ve /d "Xftp.xfp" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\Classes\.xsh" /f /ve /d "Xshell.xsh" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\Classes\.xts" /f /ve /d "Xtransport.xts" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\Classes\.xcas" /f /ve /d "Xstart.session" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\Classes\.xdts" /f /ve /d "Xmanager.session" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\Classes\Xftp.xfp" /f /ve /d "Xftp session" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\Classes\Xftp.xfp\DefaultIcon" /f /ve /d "%~dp0Xftp.exe,0" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\Classes\Xftp.xfp\shell\open\command" /f /ve /d "\"%~dp0Xftp.exe\" \"%%1\"" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\Classes\Xshell.xsh" /f /ve /d "Xshell session" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\Classes\Xshell.xsh\DefaultIcon" /f /ve /d "%~dp0Xshell.exe,0" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\Classes\Xshell.xsh\shell\open\command" /f /ve /d "\"%~dp0Xshell.exe\" \"%%1\"" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\Classes\Xtransport.xts\shell\open" /f /ve /d "" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\Classes\Xtransport.xts\shell\open\command" /f /ve /d "\"%~dp0Xtransport.exe\" -f \"%%1\"" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\Classes\Xstart.session" /f /ve /d "Xstart session" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\Classes\Xstart.session\DefaultIcon" /f /ve /d "%~dp0Xrcmd.exe,0" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\Classes\Xstart.session\shell\open\command" /f /ve /d "\"%~dp0Xrcmd.exe\" \"%%1\"" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\Classes\Xmanager.session" /f /ve /d "Xmanager session" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\Classes\Xmanager.session\DefaultIcon" /f /ve /d "%~dp0Xmanager.exe,0" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\Classes\Xmanager.session\shell\open\command" /f /ve /d "\"%~dp0Xmanager.exe\" \"%%1\"" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Xagent.exe" /f /ve /d "%~dp0Xagent.exe" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Xftp.exe" /f /ve /d "%~dp0Xftp.exe" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Xshell.exe" /f /ve /d "%~dp0Xshell.exe" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Xrcmd.exe" /f /ve /d "%~dp0Xrcmd.exe" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Xmanager.exe" /f /ve /d "%~dp0Xmanager.exe" /reg:32 >NUL 2>NUL
::刷新会话格式图标
ASSOC .=. >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\Xftp\7" /f /v "Path" /d "%~dp0\" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\NetSarang\Xmanager\7" /f /v "Path" /d "%~dp0\" /reg:32 >NUL 2>NUL
::关于显示版本号（如无该键值关于对话框则不显示版本号）
reg add "HKLM\SOFTWARE\NetSarang\Xshell\7" /f /v "Version" /d "7.0.0144" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\NetSarang\Xftp\7" /f /v "Version" /d "7.0.0144" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\NetSarang\Xmanager\7" /f /v "Version" /d "7.0.0144" /reg:32 >NUL 2>NUL
::必要产品检测信息（如果不存这二进制数据在则启动失败）
reg add "HKLM\SOFTWARE\NetSarang\Xshell\7" /f /v "MagicCode" /t REG_BINARY /d "f0fd7f4d6ab3300cb5717151efd35618e4070b001100" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\NetSarang\Xftp\7" /f /v "MagicCode" /t REG_BINARY /d "f0fd7f4d6ab3300cb5717151efd35618e4070b001100" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\NetSarang\Xmanager\7" /f /v "MagicCode" /t REG_BINARY /d "2f8cbc511fa1b8dc3d69683d1041829be80706001a00" /reg:32 >NUL 2>NUL
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDlls" /f /v "%~dp0XshellCore.tlb" /reg:32 >NUL 2>NUL

::Xshell的设置
::隐藏菜单栏（按alt可显示）
reg add "HKCU\SOFTWARE\NetSarang\Xshell\7\Layout\current" /f /v "MenuBar" /t REG_DWORD /d "0" /reg:32 >NUL 2>NUL
::显示标准按钮
reg add "HKCU\SOFTWARE\NetSarang\Xshell\7\Layout\current" /f /v "ToolBar" /t REG_DWORD /d "1" /reg:32 >NUL 2>NUL
::隐藏地址栏
reg add "HKCU\SOFTWARE\NetSarang\Xshell\7\Layout\current" /f /v "AddressBar" /t REG_DWORD /d "0" /reg:32 >NUL 2>NUL
::隐藏链接栏
reg add "HKCU\SOFTWARE\NetSarang\Xshell\7\Layout\current" /f /v "LinksBar" /t REG_DWORD /d "0" /reg:32 >NUL 2>NUL
::隐藏会话管理器
reg add "HKCU\SOFTWARE\NetSarang\Xshell\7\Layout\current" /f /v "SessionManager" /t REG_DWORD /d "0" /reg:32 >NUL 2>NUL
::锁定工具栏
reg add "HKCU\SOFTWARE\NetSarang\Xshell\7\Layout\current" /f /v "RebarLocked" /t REG_DWORD /d "1" /reg:32 >NUL 2>NUL

::Xftp的设置
::隐藏链接栏
reg add "HKCU\SOFTWARE\NetSarang\Xftp\7\Layout\default" /f /v "LinkBar" /t REG_DWORD /d "0" /reg:32 >NUL 2>NUL
::隐藏菜单栏（按alt可显示）
reg add "HKCU\SOFTWARE\NetSarang\Xftp\7\Layout\default" /f /v "MenuBar" /t REG_DWORD /d "0" /reg:32 >NUL 2>NUL
::隐藏快速连接栏
reg add "HKCU\SOFTWARE\NetSarang\Xftp\7\Layout\default" /f /v "QuickConnect" /t REG_DWORD /d "0" /reg:32 >NUL 2>NUL

reg add "HKLM\SOFTWARE\Classes\TypeLib\{76F8E8FE-E047-44E6-80B1-302E70CB6B27}\1.0\0\win32" /f /ve /d "%~dp0XshellCore.tlb" /reg:32 >NUL 2>NUL

mkdir "%USERPROFILE%\Documents\NetSarang Computer\7\Xshell\Sessions
mkdir "%USERPROFILE%\Documents\NetSarang Computer\7\Xftp
::默认会话属性
copy default.xshell "%USERPROFILE%\Documents\NetSarang Computer\7\Xshell\Sessions\default"
::自定义快捷键
copy CustomKeyMap.ckm "%USERPROFILE%\Documents\NetSarang Computer\7\Xshell"
::其它设置
copy Xshell.ini "%USERPROFILE%\Documents\NetSarang Computer\7\Xshell"
copy Xftp.ini "%USERPROFILE%\Documents\NetSarang Computer\7\Xftp"

::创建桌面快捷方式
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")
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"") & ""\Xmanager.lnk""):b.TargetPath=""%~sdp0Xbrowser.exe"":b.WorkingDirectory=""%~sdp0\"":b.Save:close")

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