mirror of https://github.com/wh1te909/rmmagent.git
add edit winsvc
This commit is contained in:
parent
d2c9ec7f6d
commit
88085847a5
|
@ -113,6 +113,17 @@ func (a *WindowsAgent) RunRPC() {
|
||||||
ret.Encode(retData)
|
ret.Encode(retData)
|
||||||
msg.Respond(resp)
|
msg.Respond(resp)
|
||||||
}(payload)
|
}(payload)
|
||||||
|
|
||||||
|
case "editwinsvc":
|
||||||
|
go func(p *NatsMsg) {
|
||||||
|
var resp []byte
|
||||||
|
ret := codec.NewEncoderBytes(&resp, new(codec.MsgpackHandle))
|
||||||
|
svcName := p.Data["name"]
|
||||||
|
startType := p.Data["startType"]
|
||||||
|
retData := a.EditService(svcName, startType)
|
||||||
|
ret.Encode(retData)
|
||||||
|
msg.Respond(resp)
|
||||||
|
}(payload)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
nc.Flush()
|
nc.Flush()
|
||||||
|
|
|
@ -92,6 +92,52 @@ func (a *WindowsAgent) ControlService(name, action string) WinSvcResp {
|
||||||
return WinSvcResp{Success: false, ErrorMsg: "Something went wrong"}
|
return WinSvcResp{Success: false, ErrorMsg: "Something went wrong"}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *WindowsAgent) EditService(name, startupType string) WinSvcResp {
|
||||||
|
conn, err := mgr.Connect()
|
||||||
|
if err != nil {
|
||||||
|
return WinSvcResp{Success: false, ErrorMsg: err.Error()}
|
||||||
|
}
|
||||||
|
defer conn.Disconnect()
|
||||||
|
|
||||||
|
srv, err := conn.OpenService(name)
|
||||||
|
if err != nil {
|
||||||
|
return WinSvcResp{Success: false, ErrorMsg: err.Error()}
|
||||||
|
}
|
||||||
|
defer srv.Close()
|
||||||
|
|
||||||
|
conf, err := srv.Config()
|
||||||
|
if err != nil {
|
||||||
|
return WinSvcResp{Success: false, ErrorMsg: err.Error()}
|
||||||
|
}
|
||||||
|
|
||||||
|
var startType uint32
|
||||||
|
switch startupType {
|
||||||
|
case "auto":
|
||||||
|
startType = 2
|
||||||
|
case "autodelay":
|
||||||
|
startType = 2
|
||||||
|
case "manual":
|
||||||
|
startType = 3
|
||||||
|
case "disabled":
|
||||||
|
startType = 4
|
||||||
|
default:
|
||||||
|
return WinSvcResp{Success: false, ErrorMsg: "Unknown startup type provided"}
|
||||||
|
}
|
||||||
|
|
||||||
|
conf.StartType = startType
|
||||||
|
if startupType == "autodelay" {
|
||||||
|
conf.DelayedAutoStart = true
|
||||||
|
} else if startupType == "auto" {
|
||||||
|
conf.DelayedAutoStart = false
|
||||||
|
}
|
||||||
|
|
||||||
|
err = srv.UpdateConfig(conf)
|
||||||
|
if err != nil {
|
||||||
|
return WinSvcResp{Success: false, ErrorMsg: err.Error()}
|
||||||
|
}
|
||||||
|
return WinSvcResp{Success: true, ErrorMsg: ""}
|
||||||
|
}
|
||||||
|
|
||||||
func (a *WindowsAgent) GetServiceDetail(name string) WindowsService {
|
func (a *WindowsAgent) GetServiceDetail(name string) WindowsService {
|
||||||
ret := WindowsService{}
|
ret := WindowsService{}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue