728x90
728x170
[TestAction 프로젝트]
▶ CustomAction.cs
using Microsoft.Deployment.WindowsInstaller;
using System;
using System.IO;
using TestLibrary;
namespace TestAction
{
/// <summary>
/// 커스텀 액션
/// </summary>
public class CustomAction
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Public
#region 최초 설치 시작 액션 실행하기 - ExecuteFirstInstallStartAction(session)
/// <summary>
/// 최초 설치 시작 액션 실행하기
/// </summary>
/// <param name="session">세션</param>
/// <returns>액션 결과</returns>
[CustomAction]
public static ActionResult ExecuteFirstInstallStartAction(Session session)
{
ILogHelper logHelper = new FileLogHelper("d:\\", "TestNode.log");
logHelper.WriteLog($"ExecuteFirstInstallStartAction : {ApplicationEnvironment.Version}");
return ActionResult.Success;
}
#endregion
#region 최초 설치 종료 액션 실행하기 - ExecuteFirstInstallEndAction(session)
/// <summary>
/// 최초 설치 종료 액션 실행하기
/// </summary>
/// <param name="session">세션</param>
/// <returns>액션 결과</returns>
[CustomAction]
public static ActionResult ExecuteFirstInstallEndAction(Session session)
{
ILogHelper logHelper = new FileLogHelper("d:\\", "TestNode.log");
logHelper.WriteLog($"ExecuteFirstInstallEndAction : {ApplicationEnvironment.Version}");
#region 윈도우즈 서비스를 생성하고 시작한다.
try
{
string directoryPath = session["APPDIR"];
string filePath = Path.Combine(directoryPath, ApplicationEnvironment.ServiceFileName);
logHelper.WriteLog($"SERVICE FILE PATH : {filePath}");
WindowsServiceHelper.CreateWindowsService(ApplicationEnvironment.ServiceName, filePath);
logHelper.WriteLog($"SERVICE CREATED : {ApplicationEnvironment.ServiceName}");
WindowsServiceHelper.StartWindowsService(ApplicationEnvironment.ServiceName);
logHelper.WriteLog($"SERVICE STARTED : {ApplicationEnvironment.ServiceName}");
}
catch(Exception exception)
{
logHelper.WriteErrorLog(exception, "ExecuteFirstInstallEndAction Error");
}
#endregion
return ActionResult.Success;
}
#endregion
#region 업그레이드 설치 시작 액션 실행하기 - ExecuteUpgradeInstallStartAction(session)
/// <summary>
/// 업그레이드 설치 시작 액션 실행하기
/// </summary>
/// <param name="session">세션</param>
/// <returns>액션 결과</returns>
[CustomAction]
public static ActionResult ExecuteUpgradeInstallStartAction(Session session)
{
ILogHelper logHelper = new FileLogHelper("d:\\", "TestNode.log");
logHelper.WriteLog($"ExecuteUpgradeInstallStartAction : {ApplicationEnvironment.Version}");
#region 윈도우즈 서비스를 중단하고 삭제한다.
try
{
string directoryPath = session["APPDIR"];
string filePath = Path.Combine(directoryPath, ApplicationEnvironment.ServiceFileName);
logHelper.WriteLog($"SERVICE FILE PATH : {filePath}");
WindowsServiceHelper.StopWindowsService(ApplicationEnvironment.ServiceName);
logHelper.WriteLog($"SERVICE STOPPED : {ApplicationEnvironment.ServiceName}");
WindowsServiceHelper.DeleteWindowsService(ApplicationEnvironment.ServiceName);
logHelper.WriteLog($"SERVICE DELETED : {ApplicationEnvironment.ServiceName}");
}
catch(Exception exception)
{
logHelper.WriteErrorLog(exception, "ExecuteUpgradeInstallStartAction Error");
}
#endregion
return ActionResult.Success;
}
#endregion
#region 업그레이드 설치 종료 액션 실행하기 - ExecuteUpgradeInstallEndAction(session)
/// <summary>
/// 업그레이드 설치 종료 액션 실행하기
/// </summary>
/// <param name="session">세션</param>
/// <returns>액션 결과</returns>
[CustomAction]
public static ActionResult ExecuteUpgradeInstallEndAction(Session session)
{
ILogHelper logHelper = new FileLogHelper("d:\\", "TestNode.log");
logHelper.WriteLog($"ExecuteUpgradeInstallEndAction : {ApplicationEnvironment.Version}");
#region 윈도우즈 서비스를 생성하고 시작한다.
try
{
string directoryPath = session["APPDIR"];
string filePath = Path.Combine(directoryPath, ApplicationEnvironment.ServiceFileName);
logHelper.WriteLog($"SERVICE FILE PATH : {filePath}");
WindowsServiceHelper.CreateWindowsService(ApplicationEnvironment.ServiceName, filePath);
logHelper.WriteLog($"SERVICE CREATED : {ApplicationEnvironment.ServiceName}");
WindowsServiceHelper.StartWindowsService(ApplicationEnvironment.ServiceName);
logHelper.WriteLog($"SERVICE STARTED : {ApplicationEnvironment.ServiceName}");
}
catch(Exception exception)
{
logHelper.WriteErrorLog(exception, "ExecuteFirstInstallEndAction Error");
}
#endregion
return ActionResult.Success;
}
#endregion
#region 설치 제거 시작 액션 실행하기 - ExecuteUninstallStartAction(session)
/// <summary>
/// 설치 제거 시작 액션 실행하기
/// </summary>
/// <param name="session">세션</param>
/// <returns>액션 결과</returns>
[CustomAction]
public static ActionResult ExecuteUninstallStartAction(Session session)
{
ILogHelper logHelper = new FileLogHelper("d:\\", "TestNode.log");
logHelper.WriteLog($"ExecuteUninstallStartAction : {ApplicationEnvironment.Version}");
#region 윈도우즈 서비스를 중단하고 삭제한다.
try
{
string directoryPath = session["APPDIR"];
string filePath = Path.Combine(directoryPath, ApplicationEnvironment.ServiceFileName);
logHelper.WriteLog($"SERVICE FILE PATH : {filePath}");
WindowsServiceHelper.StopWindowsService(ApplicationEnvironment.ServiceName);
logHelper.WriteLog($"SERVICE STOPPED : {ApplicationEnvironment.ServiceName}");
WindowsServiceHelper.DeleteWindowsService(ApplicationEnvironment.ServiceName);
logHelper.WriteLog($"SERVICE DELETED : {ApplicationEnvironment.ServiceName}");
}
catch(Exception exception)
{
logHelper.WriteErrorLog(exception, "ExecuteUpgradeInstallStartAction Error");
}
#endregion
return ActionResult.Success;
}
#endregion
#region 설치 제거 종료 액션 실행하기 - ExecuteUninstallEndAction(session)
/// <summary>
/// 설치 제거 종료 액션 실행하기
/// </summary>
/// <param name="session">세션</param>
/// <returns>액션 결과</returns>
[CustomAction]
public static ActionResult ExecuteUninstallEndAction(Session session)
{
ILogHelper logHelper = new FileLogHelper("d:\\", "TestNode.log");
logHelper.WriteLog($"ExecuteUninstallEndAction : {ApplicationEnvironment.Version}");
return ActionResult.Success;
}
#endregion
}
}
728x90
그리드형(광고전용)
'C# > Advanced Installer' 카테고리의 다른 글
[C#/ADVANCED INSTALLER] updates.txt 파일 정보 구하기 (0) | 2021.09.12 |
---|---|
[C#/ADVANCED INSTALLER] 커스텀 액션을 사용해 윈도우즈 서비스 실행하기 (기능 개선) (0) | 2021.08.31 |
[C#/ADVANCED INSTALLER] 커스텀 액션 사용하기 (0) | 2021.01.05 |
[C#/ADVANCED INSTALLER] 업데이트 프로그램 강제 실행 코드 추가하기 (0) | 2020.05.30 |