Merge pull request #392 from derekwbrown/add_username

[windows] add implementation for process.Username()
This commit is contained in:
shirou 2017-07-09 00:54:15 +09:00 committed by GitHub
commit ae1481820a
1 changed files with 21 additions and 2 deletions

View File

@ -181,8 +181,26 @@ func (p *Process) Status() (string, error) {
return "", common.ErrNotImplementedError
}
func (p *Process) Username() (string, error) {
return "", common.ErrNotImplementedError
pid := p.Pid
// 0x1000 is PROCESS_QUERY_LIMITED_INFORMATION
c, err := syscall.OpenProcess(0x1000, false, uint32(pid))
if err != nil {
return "", err
}
defer syscall.CloseHandle(c)
var token syscall.Token
err = syscall.OpenProcessToken(c, syscall.TOKEN_QUERY, &token)
if err != nil {
return "", err
}
defer token.Close()
tokenUser, err := token.GetTokenUser()
user, domain, _, err := tokenUser.User.Sid.LookupAccount("")
return domain + "\\" + user, err
}
func (p *Process) Uids() ([]int32, error) {
var uids []int32
@ -412,7 +430,8 @@ func getRusage(pid int32) (*windows.Rusage, error) {
func getMemoryInfo(pid int32) (PROCESS_MEMORY_COUNTERS, error) {
var mem PROCESS_MEMORY_COUNTERS
c, err := windows.OpenProcess(windows.PROCESS_QUERY_INFORMATION, false, uint32(pid))
// PROCESS_QUERY_LIMITED_INFORMATION is 0x1000
c, err := windows.OpenProcess(0x1000, false, uint32(pid))
if err != nil {
return mem, err
}