netresource

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2022 License: MIT Imports: 11 Imported by: 2

README

go-windows-netresource

net use

// +build run

package main

import (
    "os"
    "os/exec"

    "github.com/nyaosorg/go-windows-netresource"
)

func main() {
    cancel, err := netresource.NetUse(`X:`, `\\localhost\C$`)
    if err != nil {
        println(err.Error())
        return
    }
    defer cancel(true, false)

    cmd := exec.Command("cmd.exe", "/c", "dir", `X:\`)
    cmd.Stdout = os.Stdout
    cmd.Stderr = os.Stderr
    cmd.Stdin = os.Stdin
    cmd.Run()
}

Find file servers and their shared folders

package main

import (
    "github.com/nyaosorg/go-windows-netresource"
)

func main() {
    machines := []string{}

    err := netresource.EnumFileServer(func(node *netresource.NetResource) bool {
        machines = append(machines, node.RemoteName())
        return true
    })
    if err != nil {
        println(err.Error())
    }

    for _, name := range machines {
        println("machine:", name)
        if fs, err := netresource.NewFileServer(name); err == nil {
            fs.Enum(func(node *netresource.NetResource) bool {
                println("  ", node.RemoteName())
                return true
            })
        }
    }

    if err != nil {
        println(err.Error())
    }
}

Documentation

Index

Constants

View Source
const CONNECT_UPDATE_PROFILE = 1
View Source
const ERROR_NO_MORE_ITEMS = 259
View Source
const RESOURCEDISPLAYTYPE_NETWORK = 6
View Source
const RESOURCEDISPLAYTYPE_SERVER = 2
View Source
const RESOURCETYPE_ANY = 0
View Source
const RESOURCETYPE_DISK = 1
View Source
const RESOURCETYPE_PRINT = 2
View Source
const RESOURCEUSAGE_ALL = 19
View Source
const RESOURCEUSAGE_ATTACHED = 16
View Source
const RESOURCEUSAGE_CONNECTABLE = 1
View Source
const RESOURCEUSAGE_CONTAINER = 2
View Source
const RESOURCE_CONNECTED = 1

Code generated by go-importconst DO NOT EDIT.

View Source
const RESOURCE_CONTEXT = 5
View Source
const RESOURCE_GLOBALNET = 2
View Source
const RESOURCE_REMEMBERED = 3

Variables

This section is empty.

Functions

func EnumFileServer

func EnumFileServer(callback func(*NetResource) bool) error

EnumFileServer lists up file-servers.

func FindVacantDrive

func FindVacantDrive() (uint, error)

FindVacantDrive returns the last unused drive like 'Z'

func GetDiskFreeSpace

func GetDiskFreeSpace(rootPathName string) (free uint64, total uint64, totalFree uint64, err error)

GetDiskFreeSpace retunrs disk information.

rootPathName - string like "C:"

func NetUse

func NetUse(drive, vol string) (func(bool, bool), error)

NetUse do same thing as `net use X: \\server\path...`

drive - `X:`
vol - `server\\path\...`

returns

func(update,force) - function release the drive
    update - true: updates connection as not a persistent one
    force - true: disconnect even if open process exists.
error

func UNCtoNetDrive

func UNCtoNetDrive(uncpath string) (newpath string, closer func(bool, bool))

UNCtoNetDrive replace UNCPath to path using netdrive.

uncpath - for example \\server\path\folder\name

returns

newpath - X:\folder\name

func VolumeName

func VolumeName(drive string) (label string, fsname string, err error)

func WNetAddConnection2

func WNetAddConnection2(remote, local, user, pass string) (err error)

WNetAddConnection2 makes a connection to a network resource and can redirect a local device to the network resource

remote - UNC-Path like `\\localhost\C$`
local - local-drive like `X:`
user - username. When it is "", default username is used.
pass - password. When it is "", default passwors is used.

func WNetCancelConnection2

func WNetCancelConnection2(name string, update bool, force bool) error

WNetCancelConnection2 cancels an existing network connection.

update - true: updates connection as not a persistent one
force - true: disconnect even if open process exists.

func WNetEnum

func WNetEnum(callback func(nr *NetResource) bool) error

func WNetGetConnectionUTF16a

func WNetGetConnectionUTF16a(drive uint16) (string, error)

func WNetGetConnectionUTF16s

func WNetGetConnectionUTF16s(localName []uint16) (string, error)

Types

type Drive

type Drive struct {
	Letter rune
	Type   uint32
}

func GetDrives

func GetDrives() ([]*Drive, error)

type NetDrive

type NetDrive struct {
	Letter rune
	Remote string
}

func GetNetDrives

func GetNetDrives() ([]*NetDrive, error)

type NetResource

type NetResource struct {
	Scope       uint32
	Type        uint32
	DisplayType uint32
	Usage       uint32
	// contains filtered or unexported fields
}

func NewFileServer

func NewFileServer(name string) (*NetResource, error)

NewFileServer is constructor of NetResource for FileServer's root node.

func (*NetResource) Comment

func (nr *NetResource) Comment() string

func (*NetResource) Enum

func (nr *NetResource) Enum(callback func(*NetResource) bool) error

func (*NetResource) IsDir

func (nr *NetResource) IsDir() bool

func (*NetResource) LocalName

func (nr *NetResource) LocalName() string

func (*NetResource) ModTime

func (nr *NetResource) ModTime() time.Time

func (*NetResource) Mode

func (nr *NetResource) Mode() os.FileMode

func (*NetResource) Name

func (nr *NetResource) Name() string

func (*NetResource) Provider

func (nr *NetResource) Provider() string

func (*NetResource) RemoteName

func (nr *NetResource) RemoteName() string

func (*NetResource) Size

func (nr *NetResource) Size() int64

func (*NetResource) Sys

func (nr *NetResource) Sys() interface{}

type NetResourceHandle

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

NetResourceHandle is compatible type with "net/http".File

func (*NetResourceHandle) Close

func (this *NetResourceHandle) Close() error

func (*NetResourceHandle) Read

func (this *NetResourceHandle) Read([]byte) (int, error)

func (*NetResourceHandle) Readdir

func (this *NetResourceHandle) Readdir(_count int) ([]os.FileInfo, error)

func (*NetResourceHandle) Seek

func (this *NetResourceHandle) Seek(int64, int) (int64, error)

func (*NetResourceHandle) Stat

func (this *NetResourceHandle) Stat() (os.FileInfo, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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