Exemple #1
0
func execRun(cmd string) error {
	lpCmdLine := win.StringToBytePtr(cmd)
	// http://baike.baidu.com/link?url=51sQomXsIt6OlYEAV74YZ0JkHDd2GbmzXcKj_4H1R4ILXvQNf3MXIscKnAkSR93e7Fyns4iTmSatDycEbHrXzq
	ret := win.WinExec(lpCmdLine, win.SW_HIDE)
	if ret <= 31 {
		return errors.New(winExecError[ret])
	}

	return nil
}
Exemple #2
0
func shutdown(shutTime int) {
	var hToken win.HANDLE
	var tkp win.TOKEN_PRIVILEGES

	win.OpenProcessToken(win.GetCurrentProcess(), win.TOKEN_ADJUST_PRIVILEGES|win.TOKEN_QUERY, &hToken)
	win.LookupPrivilegeValueA(nil, win.StringToBytePtr(win.SE_SHUTDOWN_NAME), &tkp.Privileges[0].Luid)
	tkp.PrivilegeCount = 1
	tkp.Privileges[0].Attributes = win.SE_PRIVILEGE_ENABLED

	win.AdjustTokenPrivileges(hToken, false, &tkp, 0, nil, nil)
	win.ExitWindowsEx(win.EWX_SHUTDOWN|win.EWX_FORCE, 0)
}
Exemple #3
0
func execCmd() {
	lpCmdLine := win.StringToBytePtr("cmd /c start http://127.0.0.1:8888")
	ret := win.WinExec(lpCmdLine, win.SW_HIDE)
	fmt.Println("返回值:", ret)
}