[feat] register and remove CrossDeskService in the Windows installer

This commit is contained in:
dijunkun
2026-04-21 23:23:11 +08:00
parent 2be6e727ce
commit 4089e80fe8
6 changed files with 122 additions and 8 deletions

View File

@@ -8,6 +8,7 @@
!define PRODUCT_WEB_SITE "https://www.crossdesk.cn/" !define PRODUCT_WEB_SITE "https://www.crossdesk.cn/"
!define APP_NAME "CrossDesk" !define APP_NAME "CrossDesk"
!define UNINSTALL_REG_KEY "CrossDesk" !define UNINSTALL_REG_KEY "CrossDesk"
!define PRODUCT_SERVICE_NAME "CrossDeskService"
; Installer icon path ; Installer icon path
!define MUI_ICON "${__FILEDIR__}\..\..\icons\windows\crossdesk.ico" !define MUI_ICON "${__FILEDIR__}\..\..\icons\windows\crossdesk.ico"
@@ -68,14 +69,21 @@ cancelInstall:
Abort Abort
installApp: installApp:
Call StopInstalledService
SetOutPath "$INSTDIR" SetOutPath "$INSTDIR"
SetOverwrite ifnewer SetOverwrite ifnewer
; Main application executable path ; Main application executable path
File /oname=CrossDesk.exe "..\..\build\windows\x64\release\crossdesk.exe" File /oname=CrossDesk.exe "..\..\build\windows\x64\release\crossdesk.exe"
; Bundle service-side binaries required by the Windows service flow
File "..\..\build\windows\x64\release\crossdesk_service.exe"
File "..\..\build\windows\x64\release\crossdesk_session_helper.exe"
; Bundle runtime DLLs from the release output directory ; Bundle runtime DLLs from the release output directory
File "..\..\build\windows\x64\release\*.dll" File "..\..\build\windows\x64\release\*.dll"
Call RegisterInstalledService
; Write uninstall information ; Write uninstall information
WriteUninstaller "$INSTDIR\uninstall.exe" WriteUninstaller "$INSTDIR\uninstall.exe"
@@ -122,8 +130,12 @@ cancelUninstall:
Abort Abort
uninstallApp: uninstallApp:
Call UnregisterInstalledService
; Delete main executable and uninstaller ; Delete main executable and uninstaller
Delete "$INSTDIR\CrossDesk.exe" Delete "$INSTDIR\CrossDesk.exe"
Delete "$INSTDIR\crossdesk_service.exe"
Delete "$INSTDIR\crossdesk_session_helper.exe"
Delete "$INSTDIR\uninstall.exe" Delete "$INSTDIR\uninstall.exe"
; Recursively delete installation directory ; Recursively delete installation directory
@@ -148,3 +160,85 @@ SectionEnd
Function LaunchApp Function LaunchApp
Exec "$INSTDIR\CrossDesk.exe" Exec "$INSTDIR\CrossDesk.exe"
FunctionEnd FunctionEnd
Function StopInstalledService
IfFileExists "$INSTDIR\CrossDesk.exe" 0 stop_with_sc
IfFileExists "$INSTDIR\crossdesk_service.exe" 0 stop_with_sc
DetailPrint "Stopping existing CrossDesk service"
ExecWait '"$INSTDIR\CrossDesk.exe" --service-stop' $0
${If} $0 = 0
Return
${EndIf}
stop_with_sc:
DetailPrint "Stopping existing CrossDesk service via Service Control Manager"
ExecWait '"$SYSDIR\sc.exe" stop ${PRODUCT_SERVICE_NAME}' $0
${If} $0 != 0
${AndIf} $0 != 1060
${AndIf} $0 != 1062
MessageBox MB_ICONSTOP|MB_OK "Failed to stop the existing CrossDesk service. The installation will be aborted."
Abort
${EndIf}
Sleep 1500
FunctionEnd
Function RegisterInstalledService
IfFileExists "$INSTDIR\CrossDesk.exe" 0 missing_service_binary
IfFileExists "$INSTDIR\crossdesk_service.exe" 0 missing_service_binary
IfFileExists "$INSTDIR\crossdesk_session_helper.exe" 0 missing_service_binary
DetailPrint "Registering CrossDesk service"
ExecWait '"$INSTDIR\CrossDesk.exe" --service-install' $0
${If} $0 != 0
MessageBox MB_ICONSTOP|MB_OK "Failed to register the CrossDesk service. The installation will be aborted."
Abort
${EndIf}
DetailPrint "Starting CrossDesk service"
ExecWait '"$INSTDIR\CrossDesk.exe" --service-start' $0
${If} $0 != 0
ExecWait '"$INSTDIR\CrossDesk.exe" --service-uninstall' $1
ExecWait '"$SYSDIR\sc.exe" delete ${PRODUCT_SERVICE_NAME}' $1
MessageBox MB_ICONSTOP|MB_OK "The CrossDesk service was registered but could not be started. The installation will be aborted."
Abort
${EndIf}
Return
missing_service_binary:
MessageBox MB_ICONSTOP|MB_OK "CrossDesk service files are missing from the installer package. The installation will be aborted."
Abort
FunctionEnd
Function UnregisterInstalledService
IfFileExists "$INSTDIR\CrossDesk.exe" 0 unregister_with_sc
DetailPrint "Stopping CrossDesk service"
ExecWait '"$INSTDIR\CrossDesk.exe" --service-stop' $0
${If} $0 = 0
DetailPrint "Removing CrossDesk service"
ExecWait '"$INSTDIR\CrossDesk.exe" --service-uninstall' $0
${If} $0 = 0
Return
${EndIf}
${EndIf}
unregister_with_sc:
DetailPrint "Removing CrossDesk service via Service Control Manager"
ExecWait '"$SYSDIR\sc.exe" stop ${PRODUCT_SERVICE_NAME}' $0
${If} $0 != 0
${AndIf} $0 != 1060
${AndIf} $0 != 1062
MessageBox MB_ICONSTOP|MB_OK "Failed to stop the CrossDesk service. Uninstall will be aborted."
Abort
${EndIf}
Sleep 1500
ExecWait '"$SYSDIR\sc.exe" delete ${PRODUCT_SERVICE_NAME}' $0
${If} $0 != 0
${AndIf} $0 != 1060
MessageBox MB_ICONSTOP|MB_OK "Failed to remove the CrossDesk service. Uninstall will be aborted."
Abort
${EndIf}
FunctionEnd

View File

@@ -1,5 +1,11 @@
#ifndef _CROSSDESK_INTERACTIVE_STATE_H_ /*
#define _CROSSDESK_INTERACTIVE_STATE_H_ * @Author: DI JUNKUN
* @Date: 2026-04-21
* Copyright (c) 2026 by DI JUNKUN, All Rights Reserved.
*/
#ifndef _INTERACTIVE_STATE_H_
#define _INTERACTIVE_STATE_H_
#include <string> #include <string>

View File

@@ -1,5 +1,11 @@
#ifndef _CROSSDESK_SERVICE_HOST_H_ /*
#define _CROSSDESK_SERVICE_HOST_H_ * @Author: DI JUNKUN
* @Date: 2026-04-21
* Copyright (c) 2026 by DI JUNKUN, All Rights Reserved.
*/
#ifndef _SERVICE_HOST_H_
#define _SERVICE_HOST_H_
#include <Windows.h> #include <Windows.h>

View File

@@ -1,5 +1,7 @@
#include <TlHelp32.h> // clang-format off
#include <Windows.h> #include <Windows.h>
#include <TlHelp32.h>
// clang-format on
#include <WtsApi32.h> #include <WtsApi32.h>
#include <libyuv.h> #include <libyuv.h>
#include <sddl.h> #include <sddl.h>

View File

@@ -1,5 +1,11 @@
#ifndef _CROSSDESK_SESSION_HELPER_SHARED_H_ /*
#define _CROSSDESK_SESSION_HELPER_SHARED_H_ * @Author: DI JUNKUN
* @Date: 2026-04-21
* Copyright (c) 2026 by DI JUNKUN, All Rights Reserved.
*/
#ifndef _SESSION_HELPER_SHARED_H_
#define _SESSION_HELPER_SHARED_H_
#include <Windows.h> #include <Windows.h>

View File

@@ -192,7 +192,7 @@ function setup_targets()
add_files("src/service/windows/service_host.cpp") add_files("src/service/windows/service_host.cpp")
add_includedirs("src/service/windows", {public = true}) add_includedirs("src/service/windows", {public = true})
add_links("Advapi32", "Wtsapi32", "Ole32", "Userenv") add_links("Advapi32", "Wtsapi32", "Ole32", "Userenv")
add_deps("wgc_plugin") add_deps("wgc_plugin", "crossdesk_service", "crossdesk_session_helper")
add_files("scripts/windows/crossdesk.rc") add_files("scripts/windows/crossdesk.rc")
end end
end end