첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
------------------------------------------------------------------------------------------------------------------------------------------------------
728x90
728x170

■ ManagedInstallerClass 클래스의 InstallHelper 정적 메소드를 사용해 윈도우즈 서비스를 설치하거나 제거하는 방법을 보여준다.

 

▶ 예제 코드 (C#)

using System;
using System.IO;
using System.Configuration.Install;

#region 프로그램 실행하기 - Main(argumentArray)

/// <summary>
/// 프로그램 실행하기
/// </summary>
/// <param name="argumentArray">인자 배열</param>
private static void Main(string[] argumentArray)
{
    if(argumentArray.Length <= 0)
    {
        Console.WriteLine("설치 : WindowsServiceInstaller.exe [filename]");
        Console.WriteLine("제거 : WindowsServiceInstaller.exe [filename] /u");
    }
    else if(!File.Exists(argumentArray[0]))
    {
        Console.WriteLine("파일을 찾을 수 없습니다.");
    }
    else if(argumentArray.Length >= 2 && argumentArray[1] == "/u")
    {
        try
        {
            // 등록된 서비스 제거
            ManagedInstallerClass.InstallHelper(new string[] { "/u", argumentArray[0] });

            Console.WriteLine("성공적으로 제거되었습니다.");
        }
        catch(Exception exception)
        {
            Console.WriteLine(exception.Message);
        }
    }
    else
    {
        try
        {
            // 서비스 등록
            ManagedInstallerClass.InstallHelper(new string[] { argumentArray[0] });

            Console.WriteLine("성공적으로 설치되었습니다.");
        }
        catch(Exception exception)
        {
            Console.WriteLine(exception.Message);
        }
    }

    Console.ReadKey();
}

#endregion
728x90
그리드형(광고전용)
Posted by icodebroker
,