Golang-在Windows中设置系统调用用户上下文
我正在对Golang-在Windows中设置系统调用用户上下文,windows,iis,go,system-calls,Windows,Iis,Go,System Calls,我正在对WebCoreActivate和WebCoreShutdownAPI进行两次系统调用。我想添加一个用户上下文,这样当在Windows中进行系统调用时,它们将在特定用户的上下文(即该用户的权限)下运行 type WebCore struct { activated bool Handle syscall.Handle Credentials syscall.Credential } func New() (error, *WebCore) { hwe
WebCoreActivate
和WebCoreShutdown
API进行两次系统调用。我想添加一个用户上下文,这样当在Windows中进行系统调用时,它们将在特定用户的上下文(即该用户的权限)下运行
type WebCore struct {
activated bool
Handle syscall.Handle
Credentials syscall.Credential
}
func New() (error, *WebCore) {
hwebcore, err := syscall.LoadLibrary(os.ExpandEnv(`${windir}\system32\inetsrv\hwebcore.dll`))
if err != nil {
return err, nil
}
return nil, &WebCore{
activated: false,
Handle: hwebcore,
}
}
func (w *WebCore) Activate(appHostConfigPath, rootWebConfigPath, instanceName string) error {
if !w.activated {
webCoreActivate, err := syscall.GetProcAddress(w.Handle, "WebCoreActivate")
if err != nil {
return err
}
var nargs uintptr = 3
_, _, exitCode := syscall.Syscall(uintptr(webCoreActivate),
nargs,
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(appHostConfigPath))),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(rootWebConfigPath))),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(instanceName))))
if exitCode != 0 {
return fmt.Errorf("WebCoreActivate returned exit code: %d", exitCode)
}
fmt.Printf("Server Started for %+v\n", instanceName)
w.activated = true
}
return nil
}
func (w *WebCore) Shutdown(immediate int, instanceName string) error {
if w.activated {
webCoreShutdown, err := syscall.GetProcAddress(w.Handle, "WebCoreShutdown")
if err != nil {
return err
}
var nargs uintptr = 1
_, _, exitCode := syscall.Syscall(uintptr(webCoreShutdown),
nargs, uintptr(unsafe.Pointer(&immediate)), 0, 0)
if exitCode != 0 {
return fmt.Errorf("WebCoreShutdown returned exit code: %d", exitCode)
}
fmt.Printf("Server Shutdown for %+v\n", instanceName)
}
return nil
}
我一直在阅读有关exec.Command().SysProcAttr
结构的内容,以及如何通过syscall.credentials{}
结构附加特定的用户凭据。然而,这似乎仅限于通过os.exec
执行命令。如果我想将特定用户的上下文绑定到Windows中的本机系统调用,我该怎么做