示例#1
0
func runCommand(username string, domain string, password string, command []string) windows.Cmd {
	cmd := windows.Command(
		username, domain, password,
		command[0], command[1:]...,
	)
	return *cmd
}
示例#2
0
func Route(c *echo.Context) error {
	b, err := ioutil.ReadAll(c.Request().Body)
	if err != nil {
		return err
	}

	body := bodyRequest{}
	err = json.Unmarshal(b, &body)
	if err != nil {
		return err
	}

	cmd := windows.Command(body.Username, body.Domain, body.HideWindow, body.Command[0], body.Command[1:]...)
	if body.Stdin != "" {
		cmd.Stdin = strings.NewReader(body.Stdin)
	}

	res := make(map[string]interface{})
	if body.Wait {
		var stdout bytes.Buffer
		var stderr bytes.Buffer

		cmd.Stdout = &stdout
		cmd.Stderr = &stderr

		err = cmd.Run()
		if err != nil {
			log.Error(err)
			return err
		}

		res["stdout"] = stdout.String()
		res["stderr"] = stderr.String()
	} else {
		err = cmd.Start()
		if err != nil {
			log.Error(err)
			return err
		}
		res["pid"] = cmd.Process.Pid
	}

	return c.JSON(http.StatusOK, res)
}
// launch creates the application process.
// It's up to the processmanager to call this function when it makes sense.
func (a *Application) launch() {

	// In windows, `explorer.exe`, in addtion of beeing the file explorer, is
	// the application responssible of the graphical desktop environment.
	// In order to decide if `explorer.exe` should be launched as a "simple"
	// file explorer window or as a full graphical desktop, it firstly checks that
	// no instances of `explorer.exe` already runs in desktop mode and secondly,
	// check the value of the shell varible to be nothing else than
	// `explorer.exe`.
	// So if the application to be launched is `explorer.exe`, we set the shell
	// value to `explorer.exe` to get the desktop is needed.
	if a.Command[0] == `C:\Windows\explorer.exe` {
		windows.SetWinlogonShell("explorer.exe")
	}

	cmd := windows.Command(a.Username, a.Domain, a.HideWindow, a.Command[0], a.Command[1:]...)
	if a.Stdin != nil {
		cmd.Stdin = a.Stdin
	}

	cmd.Stdout = &a.Stdout
	cmd.Stderr = &a.Stderr
	a.cmdChan <- cmd
}