# class Chef::Util::Windows::NetUse

### Constants

SIZEOF_USE_INFO_2
USE_FORCE
USE_INFO_2
USE_INFO_2_TEMPLATE
USE_LOTS_OF_FORCE
USE_NOFORCE

### Public Class Methods

new(localname) click to toggle source

    # File lib/chef/util/windows/net_use.rb, line 76
    def initialize(localname)
      @localname = localname
      @name = multi_to_wide(localname)
    end

### Public Instance Methods

add(args) click to toggle source

    # File lib/chef/util/windows/net_use.rb, line 81
    def add(args)
      if args.class == String
        remote = args
        args = Hash.new
        args[:remote] = remote
      end
      args[:local] ||= @localname
      use = use_info_2(args)
      buffer = use_info_2_pack(use)
      rc = NetUseAdd.call(nil, 2, buffer, nil)
      if rc != NERR_Success
        raise ArgumentError, get_last_error(rc)
      end
    end

delete() click to toggle source

XXX should we use some FORCE here?

    # File lib/chef/util/windows/net_use.rb, line 115
    def delete
      rc = NetUseDel.call(nil, @name, USE_NOFORCE)
      if rc != NERR_Success
        raise ArgumentError, get_last_error(rc)
      end
    end

device() click to toggle source

    # File lib/chef/util/windows/net_use.rb, line 111
    def device
      get_info()[:remote]
    end

get_info() click to toggle source

    # File lib/chef/util/windows/net_use.rb, line 96
    def get_info
      ptr  = 0.chr * PTR_SIZE
      rc = NetUseGetInfo.call(nil, @name, 2, ptr)

      if rc != NERR_Success
        raise ArgumentError, get_last_error(rc)
      end

      ptr = ptr.unpack('L')[0]
      buffer = 0.chr * SIZEOF_USE_INFO_2
      memcpy(buffer, ptr, buffer.size)
      NetApiBufferFree(ptr)
      use_info_2_unpack(buffer)
    end