title: How can I run the application written in Golang as a Windows service
body: <p>I cannot use the screenshot application that I developed with the Win32 api as a Windows Background service.
  I install and run it as a Windows background service, I have no problem so far.
  My problem: The service doesn't give me a printout. Doesn't take a screenshot.
  I tried making another simple app. I tried sending a message using the <a href="https://docs.microsoft.com/en-us/windows/win32/api/debugapi/nf-debugapi-outputdebugstringw" rel="nofollow noreferrer">OutputDebugStringW</a>  function but my problem was not resolved.</p>
  <ul>
  <li>Can't develop Windows Background application with Win32 api?</li>
  <li>Why am I having this problem?</li>
  <li>How can I run my screenshot application as windows background service using win32 api?</li>
  </ul>
  <p>My Windows background service that is not producing output</p>
  <pre><code>    package main
      
      import (
          &quot;fmt&quot;
          &quot;log&quot;
          &quot;time&quot;
      
          &quot;github.com/checkgo/win&quot;
          &quot;github.com/kardianos/service&quot;
      )
      
      var logger service.Logger
      
      type program struct {
          exit chan struct{}
      }
      
      func (p *program) Start(s service.Service) error {
          if service.Interactive() {
              logger.Info(&quot;Running in terminal.&quot;)
          } else {
              logger.Info(&quot;Running under service manager.&quot;)
          }
          p.exit = make(chan struct{})
      
          // Start should not block. Do the actual work async.
          go p.run()
          return nil
      }
      func (p *program) run() {
          logger.Infof(&quot;I'm running %v.&quot;, service.Platform())
          ticker := time.NewTicker(2 * time.Second)
          for {
              select {
              case tm := &lt;-ticker.C:
                  win.OutputDebugString(fmt.Sprintf(&quot;%s : %v&quot;, &quot;This is test message&quot;, tm))
              case &lt;-p.exit:
                  ticker.Stop()
              }
          } // link to whaterver image from the web
      
      }
      func (p *program) Stop(s service.Service) error {
          // Stop should not block. Return with a few seconds.
          return nil
      }
      
      func main() {
          svcConfig := &amp;service.Config{
              Name:        &quot;GoServiceExampleSimple&quot;,
              DisplayName: &quot;Go Service Example&quot;,
              Description: &quot;This is an example Go service.&quot;,
          }
      
          prg := &amp;program{}
          s, err := service.New(prg, svcConfig)
          if err != nil {
              log.Fatal(err)
          }
          logger, err = s.Logger(nil)
          if err != nil {
              log.Fatal(err)
          }
          err = s.Run()
          if err != nil {
              logger.Error(err)
          }
      }
  </code></pre>
  <p>ScreenShot:
  <a href="https://i.stack.imgur.com/FuWjy.png" rel="nofollow noreferrer">DebugView and Windows Services Screen Capture</a></p>