Mount network location in Golang on Windows

import (

type NETRESOURCE struct {
	Scope        uint32
	Type         uint32
	DisplayType  uint32
	Usage        uint32
	lpLocalName  *uint16
	lpRemoteName *uint16
	lpComment    *uint16
	lpProvider   *uint16

func MountWindowsNetworkLocation(location string, username string, password string) error {
	h := syscall.MustLoadDLL("mpr.dll")
	c := h.MustFindProc("WNetAddConnection2W")

		Type:         uint32(1),
                // lpLocalName: syscall.StringToUTF16Ptr("R:"), uncomment this line to map a local device
		lpRemoteName: syscall.StringToUTF16Ptr(location),

	r1, _, err := c.Call(uintptr(unsafe.Pointer(&nr)),
		uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(username))), 0)

	if r1 != 0 {
		return err

	return nil


电子邮件地址不会被公开。 必填项已用*标注

This site uses Akismet to reduce spam. Learn how your comment data is processed.