File: servicetest_windows_test.go

package info (click to toggle)
golang-github-kardianos-service 1.2.4-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 324 kB
  • sloc: makefile: 40; sh: 3
file content (30 lines) | stat: -rw-r--r-- 891 bytes parent folder | download | duplicates (6)
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
// Copyright 2016 Lawrence Woodman <lwoodman@vlifesystems.com>
// Use of this source code is governed by a zlib-style
// license that can be found in the LICENSE file.

package service_test

import (
	"os"
	"syscall"
	"testing"
)

func interruptProcess(t *testing.T) {
	dll, err := syscall.LoadDLL("kernel32.dll")
	if err != nil {
		t.Fatalf("LoadDLL(\"kernel32.dll\") err: %s", err)
	}
	p, err := dll.FindProc("GenerateConsoleCtrlEvent")
	if err != nil {
		t.Fatalf("FindProc(\"GenerateConsoleCtrlEvent\") err: %s", err)
	}
	// Send the CTRL_BREAK_EVENT to a console process group that shares
	// the console associated with the calling process.
	// https://msdn.microsoft.com/en-us/library/windows/desktop/ms683155(v=vs.85).aspx
	pid := os.Getpid()
	r1, _, err := p.Call(syscall.CTRL_BREAK_EVENT, uintptr(pid))
	if r1 == 0 {
		t.Fatalf("Call(CTRL_BREAK_EVENT, %d) err: %s", pid, err)
	}
}