kardianos / minwinsvc

A minimal windows only service stub for go that allows running any go program as a windows service.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IsAnInteractiveSession() returns false for commands run under "local system"

btrepp opened this issue · comments

The following code prints true when ran as a user,
Running it from a shell obtained via "psexec -i -s cmd.exe" . Returns false.

This is an issue in gitea (and most likely gogs) as they run the service using minwinsvc, then call the same binary to do some subtasks (somewhat like how git functions).

This causes the init code to run, (with Os.exit()) when the command is being executed in a shell, and should be not ran as a service at this point.

package main


import (
        "fmt"
        "golang.org/x/sys/windows/svc"
)

func main(){
   interactive, err := svc.IsAnInteractiveSession()
   if(err !=nil){
     panic(err)
 
   }
 
   fmt.Printf("%t\n",interactive);
}

Huh. I'm not sure I would call psexec an interactive service. Really, this actually is called from a service when called from psexec. You'll need an alternate flag or method to deal with this.