[go-nuts] os/exec exit with error: "exit status -1073741502" when it becomes a windows service

375 views
Skip to first unread message

Peter Moore

unread,
Jun 17, 2015, 8:59:59 AM6/17/15
to golan...@googlegroups.com
Hi guys,

I’m hitting exactly the same issue on Windows Server 2008 R2 (go 1.4.2 amd64) when converting a go program to a service (using https://nssm.cc/) - I even get the exact same exit status code.

The os/exec call is to PsExec (https://technet.microsoft.com/en-us/sysinternals/bb897553.aspx) to create a process as a different user (I could not find a native way in go to create a process as a different Windows user). When not running as a service, the go program executes successfully, but when running as a service (even using running the service under the same account that I can run it with directly) I get this error with this same exit code (1073741502).

If this is not a known, solved problem, I am happy to provide more detailed information (logs, code, user account details…).

Many thanks in advance!
Pete

Chris Hines

unread,
Jun 17, 2015, 9:51:25 AM6/17/15
to golan...@googlegroups.com, pmo...@mozilla.com
I don't think this problem is related to Go specifically.

A Google search for "windows service exit code 1073741502" turns up several interesting links. Of those, the most relevant one seems to be:  http://serverfault.com/questions/357549/start-exe-in-a-remote-session-with-psexec

Chris

Konstantin Khomoutov

unread,
Jun 17, 2015, 10:45:55 AM6/17/15
to Peter Moore, golan...@googlegroups.com
On Wed, 17 Jun 2015 12:43:49 +0200
Peter Moore <pmo...@mozilla.com> wrote:

[...]
> to create a process as a different user (I could not find a native way
> in go to create a process as a different Windows user).
[...]

There can't be a "native" way to do that because Go is cross-platform,
and the details of escalating one's privileges differ drastically
across platforms.

IMO, what you should instead do is to resort to an approach standard to
Go, and use direct Windows calls through the standard syscall package.

Contrary to how this sounds, this is not actually hard.
You can do it either by hand (as a quick example, see [1]) or use a
generator (that's what Go standard library does, and, on a simpler
scale, does the well-known ODBC package [2]).

The source code of the Go standard library is abundant with good usage
examples of the syscall package, so just look at it.

1. http://stackoverflow.com/a/23744350/720999
2. https://github.com/alexbrainman/odbc/tree/master/api

brainman

unread,
Jun 17, 2015, 10:09:20 PM6/17/15
to golan...@googlegroups.com, pmo...@mozilla.com
On Wednesday, 17 June 2015 22:59:59 UTC+10, Peter Moore wrote:

> ... 

Windows service programs run in a different environment than desktop programs. Different rules apply.

It is difficult to know what to suggest, given you don't tell us what the problem is. But I wouldn't use any external programs. When you use external programs you lose fine control of what is happening - you don't know what Windows APIs external programs call and what results they get. I would just implement this service myself - this way I can see what is happening step by step. You can use Windows Event Log (or disk file) to trace all problems. It should not be difficult to create service in Go - golang.org/x/sys/windows/svc/example shows how.

Alex

Peter Moore

unread,
Jun 18, 2015, 6:28:10 AM6/18/15
to brainman, Chris Hines, Konstantin Khomoutov, golan...@googlegroups.com
Many thanks to all three of you (Alex, Chris, Konstantin) for your kind replies and helpful suggestions, especially considering it turned out not to be a go issue at all. I will be working my way through the examples, and will write up a blog post once it is all done. I appreciate all the pointers you have given me.

Kind regards,
Pete
Reply all
Reply to author
Forward
0 new messages