1
// Copyright 2012 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
12
"github.com/gabriel-samfira/sys/windows"
15
func allocSid(subAuth0 uint32) (*windows.SID, error) {
17
err := windows.AllocateAndInitializeSid(&windows.SECURITY_NT_AUTHORITY,
18
1, subAuth0, 0, 0, 0, 0, 0, 0, 0, &sid)
25
// IsAnInteractiveSession determines if calling process is running interactively.
26
// It queries the process token for membership in the Interactive group.
27
// http://stackoverflow.com/questions/2668851/how-do-i-detect-that-my-application-is-running-as-service-or-in-an-interactive-s
28
func IsAnInteractiveSession() (bool, error) {
29
interSid, err := allocSid(windows.SECURITY_INTERACTIVE_RID)
33
defer windows.FreeSid(interSid)
35
serviceSid, err := allocSid(windows.SECURITY_SERVICE_RID)
39
defer windows.FreeSid(serviceSid)
41
t, err := windows.OpenCurrentProcessToken()
47
gs, err := t.GetTokenGroups()
51
p := unsafe.Pointer(&gs.Groups[0])
52
groups := (*[2 << 20]windows.SIDAndAttributes)(p)[:gs.GroupCount]
53
for _, g := range groups {
54
if windows.EqualSid(g.Sid, interSid) {
57
if windows.EqualSid(g.Sid, serviceSid) {