블로그 이미지
010-9967-0955 보미아빠

카테고리

보미아빠, 석이 (500)
밥벌이 (16)
싸이클 (1)
일상 (1)
Total
Today
Yesterday

달력

« » 2024.4
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

공지사항

최근에 올라온 글

1. service 프로그램으로 만들기전 console application 으로 완전체를 만든다 


2. 서비스 디버깅

1) service 로 돌때 디버깅이 가능하게 하려면 몇몇 절차를 거쳐야 한다. 

- services.msc 에서 설치된 서비스의 로그온에 사용자와 상호작용을 체크 

- 디버그 > 모듈에서 지정된 pdb 를 로딩하고 ms public 심벌을 모두 로딩한다. 

- visual studio 에서 프로세스에 연결한다. 

- 적당한 break point 를 걸고 작업 

2) service app 은 f11 로 일반프로그램처럼 디버깅이 자연스럽게 되지 않으므로 

   시작 포인트를 2개 만들어 console 과 windows service 로 둘 다 사용할 수 있도록 한다. 

1) Service1.cs 에 method 를 추가한다. 

   시작포인트를 2개 만들기 위해 아래와 같이 수정한다. 

   파란 부분을 주석을 제거하고 사용하면 된다. 


    public partial class Service1 : ServiceBase

    {

        public Service1()

        {

            InitializeComponent();

        }


        protected override void OnStart(string[] args)

        {

            CXeMover cXeMover = new CXeMover();

            Thread thread = new Thread(() => cXeMover.start());

            thread.Start(); // 지속적인 while 프로그램은 thread 로 시작하지 않으면 service 시작이 안된다. 

        }


        protected override void OnStop()

        {

        }

        

        ////추가된 method 

        //internal void TestStartupAndStop()

        //{

        //    string[] args = { "" };

        //    this.OnStart(args);

        //    Console.ReadLine();

        //    this.OnStop();

        //}

    }

2) Program.cs 의 main 을 변경한다. 

   역시 파란색 부분을 주석제거하고 사용하면된다. 

 static class Program

    {

        /// <summary>

        /// 해당 응용 프로그램의 주 진입점입니다. 

        /// </summary>

        /// 


        static void Main()

        {

            ServiceBase[] ServicesToRun;

            ServicesToRun = new ServiceBase[] 

            { 

                new Service1() 

            };

            ServiceBase.Run(ServicesToRun);

        }


        //static void Main()

        //{

        //    if (Environment.UserInteractive)

        //    {

        //        Service1 service1 = new Service1();

        //        service1.TestStartupAndStop();

        //    }

        //    else

        //    {

        //        ServiceBase[] ServicesToRun;

        //        ServicesToRun = new ServiceBase[] { new Service1() };

        //        ServiceBase.Run(ServicesToRun);

        //    }

        //}

    }

3) 솔루션의 속성 변경 

   출력형식에서 Windows 응용 프로그램을 console 로 시작할 경우 콘솔 응용프로그램으로 변경 한다. 

3. root 폴더의 인식이 Console 과 다르므로 다음을 참고한다. 

   테스트를 위해서 아래와 같이 파일 생성코드를 간단히 작성하는것이 도움이 된다. 

1) Service1.cs 의 OnStart 와 OnStop method 를 수정한다. 

        protected override void OnStart(string[] args)

        {

            System.IO.File.Create(AppDomain.CurrentDomain.BaseDirectory + "Onstart.txt");

        }


        protected override void OnStop()

        {

            System.IO.File.Create(AppDomain.CurrentDomain.BaseDirectory + "OnStop.txt");

        }

2) 빌드에서 debug 일때만 동작하는 코드를 추가하기 위해서는 아래와 같은 속성을 사용한다. 

#if DEBUG

            Service1 myService = new Service1();

            myService.OnDebug();

            System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);

#else             

            ServiceBase[] ServicesToRun;

            ServicesToRun = new ServiceBase[] 

            { 

                new Service1() 

            };

            ServiceBase.Run(ServicesToRun);

#endif

3) 서비스 인스톨 후 바로 시작하게 할려면 다음과 같은 코드를 이용한다. 

Service1.cs 에서 이벤트 추가 후 (번개표시를 눌러 인스톨 후 작업할 것을 작성한다.)

        private void serviceInstaller1_AfterInstall(object sender, InstallEventArgs e)

        {

            new ServiceController(serviceInstaller1.ServiceName).Start();

        }


3. 수동 인스톨

x64의 경우 관리자모드로 x64 네이티브 도구 명령 프로프트를 이용해서 

D:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\Shortcuts

   등록   installutil xEventsMover.exe 

   삭제   installutil /u xEventsMover.exe 


4. 자동인스톨 

MSI 인스톨러를 이용해 작업할 경우 

인스톨러에 기본이 32비트 installutil 을 사용하도록 되어 있다. 

프로젝트의 속성중 TargetPlatform 을 x64 로 바꾸어 줘야지만 컴파일이 된다. 컴파일이 되고난 이후라도 설치시 에러가 난다. badImage ....1001 이라고 발생한다. 이때는 Orac 를 이용해서 프로그램 데이터베이스를 직접 수정해 주어야 한다. 


I have finally figured this out - it has NOTHING to do with architecture, references or any other nonsense and everything to do with the installer itself. As this article explains - http://blogs.msdn.com/b/heaths/archive/2006/02/01/64-bit-managed-custom-actions-with-visual-studio.aspx - the Visual Studio Installer, by default, uses a 32 bit DLL and that is what causes the failures.

To overcome this problem, simply follow these steps:

1.Make sure that you go into the Properties => Build tab for every project and set the Target Platform to x64

2.Click on the name of your Installation project and then Properties and ensure that the Target Platform is x64

3.Build your solution - if the solution does not compile, right click and Unload Project and then Load Porject for those projects whose references fail.

4.Go to http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=3138 and download and install the 7.0 INstaller SDK

5.Go into the C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin folder and install Orca by double-clicking on the Orca.Msi file

6.Run Orca and open your project's MSI folder

7.Select the Binary table 

8.Double click the cell [Binary Data] for the record InstallUtil

9.Make sure "Read binary from filename" is selected

10.Click the Browse button Browse to C:\Windows\Microsoft.NET\Framework64\v4.0.30319

11.Select InstallUtilLib.dll

12.Click the Open button and then the OK button


Orca.MSI 는 windwos sdk 를 깔아야지만 생기나 편의성을 위해서 다운받을수 있게 업로드 해둔다. 


OrcaMSI.zip


InstallUtilLib.zip


만약 지속적으로 x64만 컴파일 해야 한다면 x86의 installUtil 이미지를 x64의 이미지로 교체하면 된다. 

아 ~ 돌아버릴뻔 했어유~


1. C:\Windows\Microsoft.NET\Framework\v4.0.30319 의 InstallUtil.exe, InstallUtil.exe.conifg, installUtilLib.exe 를 백업한다. (사용자 권한이 Trustedinstaller 로 되어 있으니 이를 Administrator 로 변경한 후 파일 삭제)


1.1 각 파일의 속성을 클릭해 그룹 또는 사용자 이름에 administrator 를 선택하고 고급 소유자를
1.2 administrator 로 변경한다. 

1.3 각 파일에 administrator 에 full 권한을 준다. 

1.4 파일삭제 


2. C:\Windows\Microsoft.NET\Framework64\v4.0.30319 의 3파일을 x86 위치로 복사해 넣는다. 

3. 파일권한 변경은 구글에서 찾아보세요~ 



6. 전체적인 절차는 웹강좌나 동영상 강의가 잘 되어 있으니 참고한다. 

http://nsstbg.tistory.com/7

https://www.youtube.com/watch?v=cp2aFNtcZfk


7. install shield 는 훨씬 더 강력하다. sql express 의 자동설치 sql script 돌리기 등이 가능하다. 


끝 !










Posted by 보미아빠
, |

최근에 달린 댓글

최근에 받은 트랙백

글 보관함