diff options
| author | Dan Engelbrecht <[email protected]> | 2025-01-08 10:32:27 +0100 |
|---|---|---|
| committer | Dan Engelbrecht <[email protected]> | 2025-01-08 10:32:27 +0100 |
| commit | a8a7155e9620ab1c02136662905f09e2fa7a6f18 (patch) | |
| tree | baa41cf8f0a11e9ad9c50dd6d3b4d83d009449fc /src | |
| parent | Merge remote-tracking branch 'origin/de/zen-service-command' into de/zen-serv... (diff) | |
| download | zen-a8a7155e9620ab1c02136662905f09e2fa7a6f18.tar.xz zen-a8a7155e9620ab1c02136662905f09e2fa7a6f18.zip | |
check if service is already installed before attempting install
Diffstat (limited to 'src')
| -rw-r--r-- | src/zen/cmds/service_cmd.cpp | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/src/zen/cmds/service_cmd.cpp b/src/zen/cmds/service_cmd.cpp index 51b41f2a0..aede68573 100644 --- a/src/zen/cmds/service_cmd.cpp +++ b/src/zen/cmds/service_cmd.cpp @@ -66,7 +66,7 @@ WinRelaunchElevated() shExInfo.lpFile = ExecutablePath.c_str(); // Application to start shExInfo.lpParameters = CommandArguments.c_str(); // Additional parameters shExInfo.lpDirectory = CurrentDir; - shExInfo.nShow = SW_HIDE; + shExInfo.nShow = SW_SHOW; shExInfo.hInstApp = 0; DWORD ReturnCode = 1; @@ -86,7 +86,7 @@ WinRelaunchElevated() } else { - ZEN_CONSOLE("Failed to elevated, operation did not complete."); + ZEN_CONSOLE("Failed to run elevated, operation did not complete."); } return (int)ReturnCode; } @@ -226,6 +226,26 @@ ServiceCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) if (SubOption == &m_InstallOptions) { + ServiceInfo Info; + std::error_code Ec = QueryInstalledService(m_ServiceName, Info); + if (!Ec && Info.Status != ServiceStatus::NotInstalled) + { + ZEN_CONSOLE( + "Service '{}' already installed:\n" + " Status: {}\n" + " Executable: {}\n" + " CommandLineOptions: {}\n" + " Display Name: {}\n" + " Description: {}", + m_ServiceName, + ToString(Info.Status), + Info.Spec.ExecutablePath, + Info.Spec.CommandLineOptions, + Info.Spec.DisplayName, + Info.Spec.Description); + return 1; + } + #if ZEN_PLATFORM_WINDOWS if (!WinIsElevated()) { @@ -240,11 +260,11 @@ ServiceCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) } m_ServerExecutable = std::filesystem::absolute(m_ServerExecutable); - std::error_code Ec = InstallService(m_ServiceName, - ServiceSpec{.ExecutablePath = m_ServerExecutable, - .CommandLineOptions = GlobalOptions.PassthroughCommandLine, - .DisplayName = m_ServiceDisplayName, - .Description = m_ServiceDescription}); + Ec = InstallService(m_ServiceName, + ServiceSpec{.ExecutablePath = m_ServerExecutable, + .CommandLineOptions = GlobalOptions.PassthroughCommandLine, + .DisplayName = m_ServiceDisplayName, + .Description = m_ServiceDescription}); if (Ec) { ZEN_CONSOLE("Failed to install service '{}' using '{}' . Reason: '{}'", m_ServiceName, m_ServerExecutable, Ec.message()); |