winsession

package module
v0.0.0-...-51074a1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2019 License: MIT Imports: 9 Imported by: 0

README

winsession GoDoc

The winsession package provides access to windows session management APIs.

Documentation

Rendered for windows/amd64

Overview

Package winsession provides windows session management functions.

Index

Examples

Constants

This section is empty.

Variables

View Source
var Local = local

Local represents the local host.

Functions

This section is empty.

Types

type ClientInfo

type ClientInfo struct {
	ComputerName    string
	ComputerDomain  string
	EncryptionLevel encryptionlevel.Value
	AddressFamily   uint32
	Address         string
	HRes            uint16 // Horizontal resolution (pixels)
	VRes            uint16 // Vertical resolution (pixels)
	ColorDepth      colordepth.Value
	BuildNumber     uint32
}

ClientInfo holds detailed information about a remote client connected to a windows session via RDP.

func (ClientInfo) Computer

func (info ClientInfo) Computer() string

Computer returns the client computer in the form DOMAIN\NAME.

func (ClientInfo) IsZero

func (info ClientInfo) IsZero() bool

IsZero returns true if the client info is unset.

type Collection

type Collection struct {
	Host     *Host
	Sessions []Session
	Excluded []bool // Excluded[i] corresponds to Sessions[i]
}

Collection holds interim processing information while collecting sessions.

type CollectionOption

type CollectionOption interface {
	Apply(*Collection)
}

A CollectionOption is capable of applying its settings to a collection.

type Collector

type Collector int

A Collector is a collection option that collects additional information about a session.

Information will only be collected for sessions that have not been excluded by previous filtering options.

const (
	// CollectSessionInfo enables collection of detailed information about
	// each session.
	CollectSessionInfo Collector = 1 << iota

	// CollectClientInfo enables collection of detailed information about
	// remote desktop protocol clients.
	CollectClientInfo
)

func (Collector) Apply

func (c Collector) Apply(col *Collection)

Apply applies the collector to the collection.

func (Collector) Contains

func (c Collector) Contains(b Collector) bool

Contains returns true if c contains b.

func (Collector) Merge

func (c Collector) Merge(next CollectionOption) (merged CollectionOption, ok bool)

Merge attempts to merge the collector with the next option. It returns true if successful.

type Exclude

type Exclude Filter

Exclude is an exclusion filter.

func (Exclude) Apply

func (exclude Exclude) Apply(col *Collection)

Apply applies the exclusion filter to the collection.

type Filter

type Filter func(Session) bool

A Filter returns true if it matches a session.

func EqualsUser

func EqualsUser(name string) Filter

EqualsUser returns a filter that matches a session user name case-insensitively.

func MatchAll

func MatchAll(filters ...Filter) Filter

MatchAll returns true if all of the filters match the session.

MatchAll returns true if no filters are provided.

func MatchAny

func MatchAny(filters ...Filter) Filter

MatchAny returns true if any of the filters match the session.

MatchAny returns true if no filters are provided.

func MatchID

func MatchID(id ID) Filter

MatchID returns a filter that matches a session ID.

func MatchState

func MatchState(states ...connstate.Value) Filter

MatchState returns a filter that matches any of the given states.

func MatchUser

func MatchUser(matcher StringMatcher) Filter

MatchUser returns a filter that matches a session user name.

type Host

type Host struct {
	// contains filtered or unexported fields
}

Host is an open connection to a local or remote computer. It manages an open system handle internally.

Each server must be closed when it is no longer needed.

func Open

func Open(addr string) (*Host, error)

Open opens a connection to the server with the given address. If addr is empty a connection to the local server will be established.

func (*Host) Close

func (host *Host) Close() error

Close closes any system handles held by host.

func (*Host) Handle

func (host *Host) Handle() syscall.Handle

Handle returns the system handle for the connection to host.

func (*Host) Sessions

func (host *Host) Sessions(options ...CollectionOption) ([]Session, error)

Sessions returns a list of windows sessions from host.

Collection options can be provided to filter the list and collect additional session information. Options will be evaluated in order.

If a filter relies on session information gathered by one or more collector options, those options must be included before the filter.

Example
package main

import (
	"fmt"

	"github.com/gentlemanautomaton/winsession"
)

func main() {
	sessions, err := winsession.Local.Sessions(
		winsession.Include(winsession.MatchID(0)),
		winsession.CollectSessionInfo)
	if err != nil {
		fmt.Printf("Failed to retrieve session list: %v\n", err)
		return
	}

	for _, session := range sessions {
		fmt.Printf("Session %d: %s (%s)\n", session.ID, session.WindowStation, session.Info.LockState)
	}

}
Output:

Session 0: Services (Unlocked)

type ID

type ID uint32

ID is a windows session ID.

type Include

type Include Filter

Include is an inclusion filter.

func (Include) Apply

func (include Include) Apply(col *Collection)

Apply applies the inclusion filter to the collection.

type MergableCollectionOption

type MergableCollectionOption interface {
	Merge(next CollectionOption) (merged CollectionOption, ok bool)
}

A MergableCollectionOption is capable of merging with the next option in the list. Some options implement this interface when bulk operations can be performed more efficiently.

type Session

type Session struct {
	ID            ID
	WindowStation string
	State         connstate.Value
	Info          SessionInfo
	Client        ClientInfo
}

Session holds information about a windows session.

type SessionInfo

type SessionInfo struct {
	LockState      lockstate.Value
	WindowStation  string
	UserName       string
	UserDomain     string
	LogonTime      time.Time
	ConnectTime    time.Time
	DisconnectTime time.Time
	LastInputTime  time.Time
	CurrentTime    time.Time
}

SessionInfo holds detailed information about a windows session.

func (SessionInfo) IsZero

func (info SessionInfo) IsZero() bool

IsZero returns true if the session info is unset.

func (SessionInfo) User

func (info SessionInfo) User() string

User returns the session's user in the form DOMAIN\USER.

type StringMatcher

type StringMatcher func(string) bool

A StringMatcher is a function that matches strings

Directories

Path Synopsis
cmd
Package wtsapi provides low-level access to the Remote Desktop Services API.
Package wtsapi provides low-level access to the Remote Desktop Services API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL